1

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
M--
  • 25,431
  • 8
  • 61
  • 93
  • Can you make your post [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example)? Please include your data using `dput()` and any other relevant code (e.g. `library()`). – jrcalabrese Jan 25 '23 at 18:03

0 Answers0