1

I've got an R data.frame TAB with the following content:

A A
A B
A C
B A
B D

What I would like to get is a list of vectors/lists:

A -> A, B, C
B -> A, D

I can do this with a for loop that looks something like this:

for (i in 1:2){
    V[[i]]<-TAB[which(is.element(TAB[,1],UA[i])),2]
}

Is there a more convenient way of doing this that avoids the for loop?

4

1 に答える 1

1

その場合、問題を解決するためのスニペットは次のとおりです。

mysplit = split(dd$y, dd$x)
myresult = lapply(mysplit, as.character)
于 2013-09-24T22:11:29.817 に答える