0

I have a large data set of species (column 1) and associated character data (column 2). I want to create an output of all unique data values for each species. Here are some dummy data:

species<-c("A","A","A","B","B","B","C","C","C")
value<-c("x","x","y","x","y","z","z","z","z")
df<-data.frame(species,value)
df

species value 1 A x 2 A x 3 A y 4 B x 5 B y 6 B z 7 C z 8 C z 9 C z

I first wanted to see counts for each value by species. To do this, I used table() with(df, table(species,value)) value species x y z A 2 1 0 B 1 1 1 C 0 0 3

Now, I would like to be able to list the different values for each species. For example, I am looking for something like this:

species unique.values A x,y B x,y,z C z

Ideas for the best way to do something like this?

Adrienne
  • 11
  • 1
  • 5
    A similar question was asked by somebody within half an hour. `aggregate(value~species, unique(df), toString)` http://stackoverflow.com/questions/27843998/r-filter-data-frame-with-unique-fields/27844065#27844065 – akrun Jan 08 '15 at 16:59
  • Homework problems abound. – IRTFM Jan 08 '15 at 19:59

0 Answers0