r - Counting unique items in data frame -


I want a simple number of the number of topics in each condition of a study. The data looks something like this:

  subject conductor observer variable 1234 1 1 12 1234 1 2 14 2143 2 1 9 3456 1 1 12 3456 1 2 14 3456 1 3 13 etc. etc.   

This is a large dataset and it is not always clear how many unique topics contribute in each condition, etc.

I have this data in the frame.

What do I want

  cond of ss 1 122 2 98   

Where for each "status" I get a count In that situation, unique SS's contribution is the number of data it seems that painful should be simple. plyr to use the ddply function

Package:

  Required (plyr) df & lt; - data.frame (subjectid = sample (1: 3,7, t), cond = sample (1: 2,7, T), audience = sample (1: 7)) gt; Ddply (df. (Cond), abbreviation, Salt / Length (unique (subjectid)) Capacity 1 1 2 2 2   

ddply Function cond variable, and produces the summary column NumSubs for each sub-data frame.

Comments