【发布时间】:2017-03-02 16:04:18
【问题描述】:
目前我有一个循环将行从一个数据帧添加到另一个主数据帧。不幸的是,它将字符转换为数字,但我不希望这样。如何在保留字符的同时获得以下 for 循环以将一个数据帧中的行添加到主数据帧中?
AnnotationsD <- data.frame(x = vector(mode = "numeric",
length = length(x)), type = 0, label = 0, lesion = 0)
x = c(1,2)
for(i in length(x)){
D = data.frame(x = i, type = c("Distance"),
label = c("*"), lesion = c("Wild"))
AnnotationsD[[i,]] <- D[[i]]
}
所以我想从中得出的结论是:
x type label lesion
1 1 Distance * Wild
2 2 Distance * Wild
【问题讨论】:
标签: r for-loop dataframe character