w*******n 发帖数: 469 | 1 请问下面的R Code 怎么用Loop来实现?
这里的comb是list.
先谢谢了!
comb$I.1<-as.integer(as.character(comb$I.1))
comb$I.2<-as.integer(as.character(comb$I.2))
comb$I.3<-as.integer(as.character(comb$I.3))
comb$I.4<-as.integer(as.character(comb$I.4))
comb$I.5<-as.integer(as.character(comb$I.5)) |
b*******x 发帖数: 100 | 2 我是菜鸟,不过不知道下面是否可以帮你解决
comb <- lapply(comb,function(x){as.integer(as.character(x))})
【在 w*******n 的大作中提到】 : 请问下面的R Code 怎么用Loop来实现? : 这里的comb是list. : 先谢谢了! : comb$I.1<-as.integer(as.character(comb$I.1)) : comb$I.2<-as.integer(as.character(comb$I.2)) : comb$I.3<-as.integer(as.character(comb$I.3)) : comb$I.4<-as.integer(as.character(comb$I.4)) : comb$I.5<-as.integer(as.character(comb$I.5))
|
w*******n 发帖数: 469 | 3 looks close to my answer, but I still have trouble to get it.
【在 b*******x 的大作中提到】 : 我是菜鸟,不过不知道下面是否可以帮你解决 : comb <- lapply(comb,function(x){as.integer(as.character(x))})
|
b*******x 发帖数: 100 | 4 What kind of trouble?
【在 w*******n 的大作中提到】 : looks close to my answer, but I still have trouble to get it.
|
s*****n 发帖数: 2174 | 5 for (i in 1:5){
var.name <- paste("I.", i, sep = "")
comb[, var.name] <- as.integer(as.character(comb[, var.name]))
}
【在 w*******n 的大作中提到】 : 请问下面的R Code 怎么用Loop来实现? : 这里的comb是list. : 先谢谢了! : comb$I.1<-as.integer(as.character(comb$I.1)) : comb$I.2<-as.integer(as.character(comb$I.2)) : comb$I.3<-as.integer(as.character(comb$I.3)) : comb$I.4<-as.integer(as.character(comb$I.4)) : comb$I.5<-as.integer(as.character(comb$I.5))
|
w*******n 发帖数: 469 | 6 Great, that solves my problem.
I appreciate your nice help.
【在 s*****n 的大作中提到】 : for (i in 1:5){ : var.name <- paste("I.", i, sep = "") : comb[, var.name] <- as.integer(as.character(comb[, var.name])) : }
|
w*******n 发帖数: 469 | 7 Maybe I don't describe my problem so clearly, sorry for this.
I just need some columns of the list to do the conversion from factor to
integer. I can take those columns I like to convert to make a new list, then
try your code. It shows no errors, but the conversion didn't work by
checking the output.
【在 b*******x 的大作中提到】 : What kind of trouble?
|
b*******x 发帖数: 100 | 8 I am a little confused, I thought you want the conversion for the whole
list, anyway, your problem was solved:)
then
【在 w*******n 的大作中提到】 : Maybe I don't describe my problem so clearly, sorry for this. : I just need some columns of the list to do the conversion from factor to : integer. I can take those columns I like to convert to make a new list, then : try your code. It shows no errors, but the conversion didn't work by : checking the output.
|