Re: [R] Get a percent variable based on group

2013-01-16 Thread arun
: Tuesday, January 15, 2013 10:22 PM Subject: RE: [R] Get a percent variable based on group For example,  iris$percent <- unlist(tapply(iris$Sepal.Length,iris$Species,function(x) x/sum(iris$Sepal.Length, na.rm=TRUE))) aggregate(iris$percent, by=list(iris$Species), FUN=sum, na.rm=TRUE) this l

Re: [R] Get a percent variable based on group

2013-01-15 Thread Jeff Newmiller
As others have said, your goal is unclear to us. However, one guess I have not seen others make is if you are looking for a way to normalize within each group, perhaps you should look at ?ave which typically creates a vector just as long as your data vector and grouping vector. ---

Re: [R] Get a percent variable based on group

2013-01-15 Thread arun
" Cc: Sent: Tuesday, January 15, 2013 9:30 PM Subject: [R] Get a percent variable based on group Dear all, I'd like to get a percentage variable based on a group, but without creating a new data frame. For example: data(iris) iris$percent <-unlist(tapply(iris$Sepal.Length,iris$Species,

Re: [R] Get a percent variable based on group

2013-01-15 Thread David Winsemius
On Jan 15, 2013, at 6:30 PM, Karine Charlebois wrote: > Dear all, I'd like to get a percentage variable based on a group, but without > creating a new data frame. > For example: > data(iris) > > iris$percent <-unlist(tapply(iris$Sepal.Length,iris$Species,function(x) > x/sum(x, na.rm=TRUE)))

[R] Get a percent variable based on group

2013-01-15 Thread Karine Charlebois
Dear all, I'd like to get a percentage variable based on a group, but without creating a new data frame. For example: data(iris) iris$percent <-unlist(tapply(iris$Sepal.Length,iris$Species,function(x) x/sum(x, na.rm=TRUE))) This does not work, I should have only three standard values, respecti