zhongmiao wang
2006-Apr-22 06:52 UTC
[R] how to convert 450 columns in a dataframe from numberic to character, but leave other columns unchanged?
Hello, I can do it seperately, but there must be a method to convert the 450 columns together? By the way, Can R write a seriers of variable names in a short way, such as X1-X450? I can extract the 450 columns out and convert them to a character matrix, however, when I combined it back, they turned back to numberic automatically. I can also use I() function to preserve them as character, however, the column names cannot be used to create formular for further calculation. How to resolve this problem? Thank you so much! Zhongmiao wang
Uwe Ligges
2006-Apr-22 10:45 UTC
[R] how to convert 450 columns in a dataframe from numberic to character, but leave other columns unchanged?
zhongmiao wang wrote:> Hello, > I can do it seperately, but there must be a method to convert the 450 > columns together?Yes.> By the way, Can R write a seriers of variable names in a short way, > such as X1-X450?paste("X", 1:450, sep="")> I can extract the 450 columns out and convert them to a character > matrix, however, when I combined it back, they turned back to numbericShould not do so, please specify reproducible code that shows the problem.> automatically. I can also use I() function to preserve them as > character, however, the column names cannot be used to create formular > for further calculation. How to resolve this problem?For your data.frame dat: cn <- paste("X", 1:450, sep="") dat[,cn] <- sapply(dat[,cn], as.character) Uwe Ligges> Thank you so much! > Zhongmiao wang > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html