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
How to Strip Dollar Signs ($) from Data/ Escape Special Characters in R
Error Creating R Data.Table with Date-Time Posixlt
Why I Get This Error Writing Data to a File
Remove Duplicates Based on 2Nd Column Condition
Delete Entries with Only One Observation in a Group
How to Properly Document S4 Methods Using Roxygen2
R How to Calculate Difference Between Rows in a Data Frame
Splitting a Data Frame into Equal Parts
Modifying Ggplot Objects After Creation
Rlang::Sym in Anonymous Functions
Display Row Names in a Data.Table Object
How to Suppress the Creation of a Plot While Calling a Function in R
How to Fit a Very Wide Grid.Table or Tablegrob to Fit on a PDF Page
How to Align Multiple Ggplot2 Plots and Add Shadows Over All of Them