I have a data.frame with all character columns, I would like to convert the last two columns into numeric.> x[1:5, ] chrN start end 1 chr1 71310034 71310064 2 chr14 23354088 23354118 3 chr14 71310034 71310064 4 chr15 37759058 37759088 5 chr22 18262638 18262668 > apply(x, 2, FUN = mode) chrN start end "character" "character" "character" ____________________________________________________________________________________ Be a better friend, newshound, and [[alternative HTML version deleted]]
Henrique Dallazuanna
2008-Feb-08 17:30 UTC
[R] convertin a data frame column from character to numeric
Try this: x <- cbind(x[1],sapply(x[,2:3], as.numeric)) On 08/02/2008, joseph <jdsandjd at yahoo.com> wrote:> I have a data.frame with all character columns, I would like to convert the last two columns into numeric.> x[1:5, ] chrN start end 1 chr1 71310034 71310064 2 chr14 23354088 23354118 3 chr14 71310034 71310064 4 chr15 37759058 37759088 > 5 chr22 18262638 18262668 > apply(x, 2, FUN = mode) chrN start end "character" "character" "character" > > > > ____________________________________________________________________________________ > Be a better friend, newshound, and > > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O