Re: [R] apply function within different groups

2013-05-23 Thread arun
Hi, May be this helps: dat1- read.table(text= group var1 var2 myvar group1 1 a 100 group2 2 b 200 group2 34 c 300 group3 5 d 400 group3 6 e 500 group4 7 f 600 ,sep=,header=TRUE,stringsAsFactors=FALSE) library(plyr) ddply(dat1,.(group),summarize, f_myvar=mifunc(myvar)) #   group f_myvar #1

Re: [R] apply function within different groups

2013-05-23 Thread Estefanía Gómez Galimberti
...@yahoo.com To: Estefanía Gómez Galimberti tef...@yahoo.com Cc: R help r-help@r-project.org Sent: Thursday, May 23, 2013 12:48 PM Subject: Re: [R] apply function within different groups Hi, May be this helps: dat1- read.table(text= group var1 var2 myvar group1 1 a 100 group2 2 b 200 group2 34 c 300

Re: [R] apply function within different groups

2013-05-23 Thread arun
    7    f   600  NA A.K. From: Estefanía Gómez Galimberti tef...@yahoo.com To: arun smartpink...@yahoo.com Cc: R help r-help@r-project.org Sent: Thursday, May 23, 2013 12:08 PM Subject: Re: [R] apply function within different groups Thanks a lot!!! It works

Re: [R] apply function within different groups

2013-05-23 Thread arun
: Thursday, May 23, 2013 1:01 PM Subject: Re: [R] apply function within different groups Hi, No problem. Try: dat2-within(dat1,f_myvar-ave(myvar,group,FUN=mifunc))  dat2 #   group var1 var2 myvar f_myvar #1 group1    1    a   100  NA #2 group2    2    b   200 299 #3 group2   34    c   300