Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get data into a format that baseline will accept? #1

Open
Phenomniverse opened this issue Dec 21, 2022 · 2 comments
Open

How to get data into a format that baseline will accept? #1

Phenomniverse opened this issue Dec 21, 2022 · 2 comments

Comments

@Phenomniverse
Copy link

Hi,
I'm trying to use your baseline package to experiment with some of the baseline algorithms described in "Liland, K. H., Almøy, T., & Mevik, B.-H. (2010). Optimal Choice of Baseline Correction for Multivariate Calibration of Spectra. Applied Spectroscopy, 64(9), 1007–1016."

I want to apply it to gas chromatography data which at present is in the form of data.frames with 'rt' and 'value' columns, representing x and y axis values respectively.

I tried calling baseline using:

> baseline(as.matrix(fid_df$value, byrow=T))
Error in rep(3, p - 4) : invalid 'times' argument

But this obviously didn't work.

I have posted a question about this on stackoverflow if you are interested in sharing a response there for others to see: "https://stackoverflow.com/questions/74870099/how-to-convert-dataframe-or-vector-to-matrix-to-use-r-baseline-package-for-dat"

Alternatively I'm wondering if you could you include some documentation in the package on how to handle this type of issue, or include a function in the package to convert data.frames or vectors into the type of matrix that baseline expects?

@khliland
Copy link
Owner

The baseline package expects spectra to appear in rows, but your code creates a matrix with the spectrum in a single column. If you change the conversion from data.frame to matrix to the following it should work:

baseline(matrix(y, nrow=1))

The problem was caused by two things, using as.matrix(), which does not take the arguments you need, and using byrow=T instead of nrow=1. byrow controls the direction in which the matrix is filled, either by rows or by columns, but has no effect on the output dimensions.

The extra fuzz in the milk data is not helping here, so I will remove it in the next package update. I will also look into the possibility of allowing single spectra to be handled in vector format instead of explicitly forcing matrix input.

I also added the same answer to Stack Overflow.

@Phenomniverse
Copy link
Author

Thank you very much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants