Sunday 13 January 2019

R: Not meaningful for factors even though its data type is numeric




I'm trying to filter by a column which has a "numeric" type already, but it keeps telling me its not meaningful to compare it using ">".



enter image description here


Answer



We can convert those factor columns to numeric



library(dplyr)
library(magrittr)

mydata %<>%
mutate_if(is.factor, funs(as.numeric(as.character(.))))





Or using base R



i1 <- sapply(mydata, is.factor)
mydata[i1] <- lapply(mydata[i1], function(x) as.numeric(as.character(x)))



and then the code should work


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...