R * Not Meaningful for Factors Error

Trouble sub-setting data.frame/not meaningful for factors error

R seems to be suggesting that Data$day is a factor variable rather than number. Try typeof(Data$day) to see what R thinks that it is.

Convert it first to a character and then to a numeric using:

Data$day <- as.numeric(as.character(Data$day))

‘sum’ not meaningful for factors error using dplyr specifically

We use n() for frequency not sum()

df %>% group_by(Rptname) %>% summarise(freq = n())
# Rptname freq
# (fctr) (int)
#1 L1PA13 1
#2 L2a 4
#3 MIRb 2
#4 MLT1B 2

Or use count

df %>% count(Rptname)

R * not meaningful for factors ERROR

new[,2] is a factor, not a numeric vector. Transform it first

new$MY_NEW_COLUMN <-as.numeric(as.character(new[,2])) * 5

Error in Math.factor(c(1L, 3L, 4L, : ‘round’ not meaningful for factors

For rounding: you should either do:

df <- data.frame(a = factor(c(1.1,2.2,3.3)))
df$b = round(as.numeric(levels(df$a)[df$a]))

Or using data.table framework:

require(data.table)
setDT(df)
df[, b:= round(as.numeric(levels(a)[a]))]

After, we would need to see what is in your functions to know what's wrong...
Hope it helps.

Error in Summary.factor ‘min’ not meaningful for factors!! How can I eliminate this error?

You could use as.numeric in lapply like this:

test<-as.data.frame(lapply(test, function(x) {
levels(x)[levels(x) %in% na_code] <- 0
as.numeric(x) }))

Hope it helps!



Related Topics



Leave a reply



Submit