Reputation: 51
I have a question for a possible loop. Maybe there is another solution for the problem?
Here the example of my dataframe:
I want to count the values in column "to count"(always 1) if the values in column "id" are the same and write the result in column "solution?"
After that i can delete column "z" and do "unique"
I think it`s not too hard, but i do not find the right command + I got my Problems with loops :-(
Thanks for help!
Upvotes: 1
Views: 128
Reputation: 132576
You can do this all in one step:
library(plyr)
ddply(DF, .(id, x, y), summarise, sumcount=sum(to_count))
Upvotes: 1
Reputation: 15458
You can use ddply
from plyr package [Assume mydata
is your data)
library(plyr)
ddply(mydata,.(id),transform, solution=length(id))
Upvotes: 1