我目前正在寻找一种解决方案来调用 adata frame中的每一列for loop,如下所示:
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
Activity dep10 out10 dep500 -5 -15 -90 +45 +20 +32 out100
Run Code Online (Sandbox Code Playgroud)
for (i in 0:length(df)) {
newDf$rowOne <<- df$V(value of i)
}
Run Code Online (Sandbox Code Playgroud)
我想使用 的值调用V1、then V2、then等...这样我就可以修改或使用 df 数据框的内容。V3i
有什么建议么?
一个更干净的解决方案是colnames像这样循环:
iris
for (i in colnames(iris)){
print(head(iris[i]))
}
Run Code Online (Sandbox Code Playgroud)