Re: [R] Count of unique factors within another factor

2010-06-14 Thread Henrique Dallazuanna
Another possibility: rowSums(table(x) > 0) On Sun, Jun 13, 2010 at 3:08 PM, Erik Iverson wrote: > I think ?tapply will help here. But *please* read the posting guide and > provide minimal, reproducible examples! > > > Birdnerd wrote: > >> I have a data frame with two factors (sampling 'unit'

Re: [R] Count of unique factors within another factor

2010-06-14 Thread Birdnerd
Hi Dennis, Thanks for this suggestion (which I got to run!), as this code makes intuitive sense, whereas not all the other suggestions were that straightforward. I'm relatively new to programming in R and am very appreciative that you and others take time to help out where you can. Sincerely, Sa

Re: [R] Count of unique factors within another factor

2010-06-13 Thread Dennis Murphy
Hi: Another possibility: as.data.frame(with(data[!duplicated(data), ], table(unit)) unit Freq 1 1233 2 3454 HTH, Dennis On Sun, Jun 13, 2010 at 9:07 AM, Birdnerd wrote: > > I have a data frame with two factors (sampling 'unit', 'species'). I want > to > calculate the number of uni

Re: [R] Count of unique factors within another factor

2010-06-13 Thread Charles C. Berry
On Sun, 13 Jun 2010, Birdnerd wrote: I have a data frame with two factors (sampling 'unit', 'species'). I want to calculate the number of unique 'species' per 'unit.' I can calculate the number of unique values for each variable separately, but can't get a count for each ‘unit’. If I underst

Re: [R] Count of unique factors within another factor

2010-06-13 Thread jim holtman
You can also use the sqldf package: > x unit species 1 123ACMA 2 123LIDE 3 123LIDE 4 123SESE 5 123SESE 6 123SESE 7 345HEAR 8 345LOHI 9 345QUAG 10 345TODI > require(sqldf) > sqldf('select unit, count(distinct species) as count from x gro

Re: [R] Count of unique factors within another factor

2010-06-13 Thread Jorge Ivan Velez
Hi there, Try with(data, tapply(species, unit, function(x) length(unique(x HTH, Jorge On Sun, Jun 13, 2010 at 12:07 PM, Birdnerd <> wrote: > > I have a data frame with two factors (sampling 'unit', 'species'). I want > to > calculate the number of unique 'species' per 'unit.' I can calcul

Re: [R] Count of unique factors within another factor

2010-06-13 Thread Erik Iverson
I think ?tapply will help here. But *please* read the posting guide and provide minimal, reproducible examples! Birdnerd wrote: I have a data frame with two factors (sampling 'unit', 'species'). I want to calculate the number of unique 'species' per 'unit.' I can calculate the number of unique

[R] Count of unique factors within another factor

2010-06-13 Thread Birdnerd
I have a data frame with two factors (sampling 'unit', 'species'). I want to calculate the number of unique 'species' per 'unit.' I can calculate the number of unique values for each variable separately, but can't get a count for each ‘unit’. > data=read.csv("C:/Desktop/sr_sort_practice.csv") > a