r - Efficient Way to Convert to Numeric -
i have converted bunch of columns factor numeric, code cumbersome. had individually convert each column, ended taking more time should. code used (only short sample - have many more columns): city1$ny <-as.numeric(levels(city1$ny))[city1$ny] city1$chi<-as.numeric(levels(city1$chi))[city1$chi] city1$la <-as.numeric(levels(city1$la))[city1$la] city1$atl<-as.numeric(levels(city1$atl))[city1$atl] city1$mia<-as.numeric(levels(city1$mia))[city1$mia] i positive instead of doing of that, could've done: city1[,citynames]<-as.numeric(levels(city1[,citynames]))[city1[,citynames]] where citynames of columns data convert.. doesn't work, get: error in as.numeric(levels(city1[, citynames]))[city1[, citynames]] : invalid subscript type 'list' can tell doing wrong? or there no easier way task other long, annoying first method? i positive instead of doing of that, could've done: city1[,citynames]<-as.numeric(levels(city1[,...