Skip to content

aggregate_spectra turns all factors to NA #3

@FedeMassetti

Description

@FedeMassetti

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions