我需要你的帮助,新的数据,我有这样的节约从data.frame
int x y z
1 0 1 0
2 1 0 0
3 0 0 1
数据帧和结果,我需要必须是这样的
int letter
1 y
2 x
3 z
我的代码是:
for (i in 1:nrow(samples))
for(j in 1:ncol(samples))
if(samples[i,][,j] == 1) print(c(i,names(samples[i,j])))
但它不显示第二列,我需要保存在一个新的data.frame,任何建议吗?谢谢。
+1。你击败了我。但是我的答案使用'names()[zzz]'而不是'colnames(zzz [])'和'zzz [,idx]'而不是'zzz [idx]',所以我会放弃它! – Frank