Hi, Suppose you created a dataframe like this: set.seed(28) dat1<-as.data.frame(simplify2array(list(letters[1:5],sample(1:20,5,replace=TRUE),6:10)),stringsAsFactors=FALSE) str(dat1) #'data.frame': 5 obs. of 3 variables: # $ V1: chr "a" "b" "c" "d" ... # $ V2: chr "1" "2" "10" "18" ... # $ V3: chr "6" "7" "8" "9" ...
dat1[,2:3]<- lapply(dat1[,2:3],as.numeric) str(dat1) #'data.frame': 5 obs. of 3 variables: # $ V1: chr "a" "b" "c" "d" ... # $ V2: num 1 2 10 18 2 # $ V3: num 6 7 8 9 10 A.K. ________________________________ From: farnoosh sheikhi <farnoosh...@yahoo.com> To: "smartpink...@yahoo.com" <smartpink...@yahoo.com> Sent: Monday, August 26, 2013 1:48 PM Subject: Loop for converting character columns to Numeric Hi there, I want to change the columns of my data from Character to numeric. Since the number of predictors are more than 100, I need to write a loop for it. Would you please help me to do that? Thanks tons. Best,Farnoosh Sheikhi ______________________________________________ R-help@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.