【发布时间】:2021-07-01 07:25:23
【问题描述】:
示例数据框
index sample
1 x
1 x
1 x
1 y
2 z
2 z
2 z
3 x
3 y
3 y
3 z
我想创建一个循环,如果相应的样本值不同,它将遍历索引列表并返回它。我正在尝试这样的事情,但我不太确定如何实现它。
for i in 1:length(index){
if(index == 1) {
check for sample values{
if there are more than one distinct value{
print(index)
else{
index + 1}}}}}
理想情况下,返回的向量是 [1] 1 3
因为 index == 2 包含所有相同的值
提前致谢!
【问题讨论】: