Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 R data.frame 选项卡,其中包含以下内容:
A A A B A C B A B D
我想得到的是向量/列表的列表:
A -> A, B, C B -> A, D
我可以用一个看起来像这样的 for 循环来做到这一点:
for (i in 1:2){ V[[i]]<-TAB[which(is.element(TAB[,1],UA[i])),2] }
有没有更方便的方法来避免 for 循环?
所以在这种情况下,解决问题的代码片段是:
mysplit = split(dd$y, dd$x) myresult = lapply(mysplit, as.character)