I have a data frame. Let\'s call him bob
:
> head(bob)
phenotype exclusion
GSM399350 3- 4- 8- 25- 44+
If you want a new data frame bobc
where every factor vector in bobf
is converted to a character vector, try this:
bobc <- rapply(bobf, as.character, classes="factor", how="replace")
If you then want to convert it back, you can create a logical vector of which columns are factors, and use that to selectively apply factor
f <- sapply(bobf, class) == "factor"
bobc[,f] <- lapply(bobc[,f], factor)