R 使用循环将数据帧细分为多个其他数据帧
我有一个名为stationDF的数据帧。R 使用循环将数据帧细分为多个其他数据帧,r,for-loop,subset,R,For Loop,Subset,我有一个名为stationDF的数据帧。 我还有从_节点到_节点的向量,到_节点的向量,对代码的简单修改如下: x_ls <- list() for (i in 1:length(from_nodes){ x_ls[[i]] <- stationDF[stationDF$from == from_nodes[i] & stationDF$to == to_nodes[i] | stationDF$from == to_n
我还有从_节点到_节点的向量,到_节点的向量
,对代码的简单修改如下:
x_ls <- list()
for (i in 1:length(from_nodes){
x_ls[[i]] <- stationDF[stationDF$from == from_nodes[i] & stationDF$to == to_nodes[i] |
stationDF$from == to_nodes[i] & stationDF$to == from_nodes[i],]
}
x <- do.call('rbind', x_ls)
x\u ls请使用dput
添加数据,并显示相同的预期输出。请阅读相关信息以及如何给出建议。
for (i in 1:length(from){
x <- stationDF[stationDF$from == from_nodes[i] & stationDF$to == to_nodes[i] |
stationDF$from == to_nodes[i] & stationDF$to == from_nodes[i],]
}
x_ls <- list()
for (i in 1:length(from_nodes){
x_ls[[i]] <- stationDF[stationDF$from == from_nodes[i] & stationDF$to == to_nodes[i] |
stationDF$from == to_nodes[i] & stationDF$to == from_nodes[i],]
}
x <- do.call('rbind', x_ls)