R 如何获取数据帧中的行索引列表?
我需要根据规则“第二列中的值==1)获取行的索引列表 例如,从这个数据帧R 如何获取数据帧中的行索引列表?,r,dataframe,R,Dataframe,我需要根据规则“第二列中的值==1)获取行的索引列表 例如,从这个数据帧 1 2 1 1 1 2 1 1 3 1 1 4 0 1 5 0 0 6 0 1 我需要一份清单 [1,2,3,4,6] 我刚从Python切换到R,在不同的数据类型中我有点不知所措。您可以试试 which(!!df$`2`) # applicable only if you only have values 0 and 1 in column 2 或 数据 df <- structure(li
1 2
1 1 1
2 1 1
3 1 1
4 0 1
5 0 0
6 0 1
我需要一份清单
[1,2,3,4,6]
我刚从Python切换到R,在不同的数据类型中我有点不知所措。您可以试试
which(!!df$`2`) # applicable only if you only have values 0 and 1 in column 2
或
数据
df <- structure(list(`1` = c(1L, 1L, 1L, 0L, 0L, 0L), `2` = c(1L, 1L,
1L, 1L, 0L, 1L)), class = "data.frame", row.names = c("1", "2",
"3", "4", "5", "6"))
dfwhich(df$Col2==1)
我想OP真的想要一个列表。如果它需要一个列表,只需做as.list
@HanaŠiková如果你认为答案有帮助,请随意接受,谢谢!
df <- structure(list(`1` = c(1L, 1L, 1L, 0L, 0L, 0L), `2` = c(1L, 1L,
1L, 1L, 0L, 1L)), class = "data.frame", row.names = c("1", "2",
"3", "4", "5", "6"))