Reputation: 350
I have some data from an experiment where each subject was run with one of 18 different lists. I need to find out how many times each list was run.
The data.frame is structured as follows:
Subject1 List1 Trial1 stuff
Subject1 List1 Trial2 stuff
Subject2 List2 Trial1 stuff
...
Subject22 List1 Trial1 stuff
Subject22 List1 Trial2 stuff
Though List1 shows up lots isn the data.set, I only want to count it if it's with a new subject. If, for instance, the above is all the subjects that were run in List1, I would have run List1 twice.
I've already written something that gets what I want, but it uses loops. I was wondering if there is some better way to go about this. Thanks.
Edit: Here is (basically) the code that I already used:
Lists <= matrix(nrow=22,ncol=2)
for (i in seq(1,22)) {
Lists[i,1] <= i
Lists[i,2] <= unique(data$List[which(data$subject==i)])
}
Upvotes: 0
Views: 45
Reputation: 1037
Are you looking for table?
> table(c("List1","List1","List2"))
List1 List2
2 1
You can do table(your second column)
Upvotes: 1