1

I have a question for a possible loop. Maybe there is another solution for the problem?

Here the example of my dataframe:

Dataframe example

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!

4

2 回答 2

1

您可以ddply从 plyr 包中使用 [假设mydata是您的数据)

library(plyr)
ddply(mydata,.(id),transform, solution=length(id))
于 2013-08-03T15:59:25.463 回答
1

您可以一步完成这一切:

library(plyr)

ddply(DF, .(id, x, y), summarise, sumcount=sum(to_count))
于 2013-08-03T15:59:40.993 回答