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

aggregate_spectra turns all factors to NA #3

Open
FedeMassetti opened this issue Aug 20, 2018 · 0 comments
Open

aggregate_spectra turns all factors to NA #3

FedeMassetti opened this issue Aug 20, 2018 · 0 comments

Comments

@FedeMassetti
Copy link

FedeMassetti commented Aug 20, 2018

When using aggregate_spectra on a SpectraDataFrame with data with more than one column containing elements of type "factor" every factor not used as id is turned into NA.

`#Loading example data
data(australia)
spectra(australia) <- sr_no ~ ... ~ 350:2500

#Generate some kind of factor
australia$fact1 <- rep(paste(letters[1:20]), each=5)
australia$fact2 <- rep(paste(letters[6:10]), times=20)
australia$fact3 <- rep(paste(letters[1:5]), times=20)

#mean
m <- aggregate_spectra(australia, fun = mean, id = 'fact3')`

Every non numeric factor in m different from fact3 is now NA. This should be expected for fact1 but not for fact2 since a is always associated with f, b with g and so on.
I obtain the same result changing the order of the factors and doing the mean using fact2 instead of fact3.

In addition if there is any column with elements of type "factor" except for the one is being considered as id the median function cannot be performed (but the mean works).
So from the previous example if fact3 is obtained like
australia$fact3 <- as.factor(rep(paste(letters[1:5]), times=20))
It will work giving NAs if I run
m <- aggregate_spectra(australia, fun = mean, id = 'fact3')
It won't work if I run
m <- aggregate_spectra(australia, fun = mean, id = 'fact2')
Giving the following error

Error in median.default(X[[i]], ...) : need numeric data

If more than one column contains factors median cannot be performed

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

1 participant