I have a file in csv format which contains two columns: samples and status(pLGG and healthy) Now I intend to add a column which turn 1 for pLGG samples and 0 for healthy ones. In fact, I want to binarize my categorical variable for further analysis but I faced this error. In the following I will add my codes and the final error.
Thanks for any help in advance!
traitData = read.csv("traits.csv")
datTraits = as.data.frame(traitData)
rownames(datTraits)=traitData$sample
datTraits = subset(datTraits , select = -c(1))
collectGarbage()
library(dplyr)
traits = datTraits
mutate(disease_state_bin = ifelse(grepl("pLGG" , traits$status),1,0))
final error:
Error in UseMethod("mutate") :
no applicable method for 'mutate' applied to an object of class "c('double', 'numeric')"
Then I did the following changes and the result was as following:
library(dplyr)
library(zoo)
mutate(disease_state_bin = ifelse(grepl("pLGG" , as.character(datTraits$status),1,0)))
last error :
Error in ifelse(grepl("pLGG", as.character(datTraits$status), 1, 0)) :
argument "yes" is missing, with no default