Counting unique items in data frame

后端 未结 4 527
予麋鹿
予麋鹿 2020-12-09 00:22

I want a simple count of the number of subjects in each condition of a study. The data look something like this:

subjectid  cond   obser variable
1234                


        
4条回答
  •  盖世英雄少女心
    2020-12-09 00:32

    Just to give you even more choice, you could also use tapply

    tapply(a$subjectid, a$cond, function(x) length(unique(x)))
    1 2 
    2 1 
    

提交回复
热议问题