try this, table(count_myData$ID)
HTH, baptiste On 29 Mar 2009, at 18:28, gianni lavaredo wrote: > > > 2009/3/29 baptiste auguie <[email protected]> > Hi, > Thanks Dott. baptiste, > > but I wish not the Sum of element but count the numeber of element > and obtain a new data.frame. Like your data.frame: myData > > library(library(plyr) > > # create a data.frame > myData <- data.frame(ID=rep(c(1:4),each=4), > count=abs(ceiling(rnorm(16,8,4)))) > #count the number of sample in each ID area > count_myData <- ddply(myData, .(ID), transform, sum = sum(count >=0, > na.rm = T)) > > > ID count sum > 1 1 0 4 > 2 1 9 4 > 3 1 11 4 > 4 1 16 4 > 5 2 9 4 > 6 2 8 4 > 7 2 11 4 > 8 2 10 4 > 9 3 16 4 > 10 3 1 4 > 11 3 0 4 > 12 3 8 4 > 13 4 8 4 > 14 4 10 4 > 15 4 11 4 > 16 4 5 4 > > now I searching to create a new DF like this: > > ID count > 1 4 > 2 4 > 3 4 > 4 4 > Thanks > Gianni > > could you provide an example for the data in "sample"? > (incidentally, note that sample is already the name of a built-in > function) > > I'm guessing you could do something like, > > > library(doBy) > summaryBy(count~ID, data= count_myData, FUN=sum) > > tested with, > > count_myData <- data.frame(ID=rep(c(1:4),each=4), > count=abs(ceiling(rnorm(16,8,4)))) > > > hope this helps, > > baptiste > > > On 29 Mar 2009, at 17:54, gianni lavaredo wrote: > > Dear R user, > > Thanks for this sunday attention about my problem. I have a > data.frame like > this example: > > count_myData > > ID: 1,1,1,1,2,2,2,3,3,3,3,3,4,4,4,4,4,4 > count: 4,4,4,4,3,3,3,5,5,5,5,5,6,6,6,6,6,6 > > this data.frame derived from this code > > count_myData <- ddply(sample, .(ID), transform, sum = sum(Z >=0, > na.rm = T)) > > with this I have the number of sample inside of area with ID 1, ID 2 > ID 3 > etc etc. > Now I need a data.frame like this > > new_myData > ID:1,2,3,4 > count:4,3,5,6 > > Thanks Gianni > > [[alternative HTML version deleted]] > > _______________________________________________ > R-sig-Geo mailing list > [email protected] > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > > _____________________________ > > Baptiste AuguiƩ > > School of Physics > University of Exeter > Stocker Road, > Exeter, Devon, > EX4 4QL, UK > > Phone: +44 1392 264187 > > http://newton.ex.ac.uk/research/emag > ______________________________ > > _____________________________ Baptiste AuguiƩ School of Physics University of Exeter Stocker Road, Exeter, Devon, EX4 4QL, UK Phone: +44 1392 264187 http://newton.ex.ac.uk/research/emag ______________________________ [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list [email protected] https://stat.ethz.ch/mailman/listinfo/r-sig-geo
