Re: [R] aggregating using 'with' function

2010-02-21 Thread AC Del Re
Wow! Jim, this is really impressive. I can't wrap my head around how you figured this out. Thank you, AC On Sun, Feb 21, 2010 at 12:02 AM, jim holtman wrote: > This will do it.  You can see two different values for id=1: > >>  x <- with(datas,  aggregate(list(r = r),  by = list(id = id, mod1 =

Re: [R] aggregating using 'with' function

2010-02-20 Thread jim holtman
This will do it. You can see two different values for id=1: > x <- with(datas, aggregate(list(r = r), by = list(id = id, mod1 = mod1),mean)) > x id mod1 r 1 11 0.980 2 41 0.640 3 71 0.490 4 101 0.180 5 12 0.295 6 52 0.490 7 82 0.330 8 11

Re: [R] aggregating using 'with' function

2010-02-20 Thread AC Del Re
OK, this is great, Jim. Last question: How about if I want the 1 copy of each id to be selected randomly versus taking the first one? Thank you, AC > On Sat, Feb 20, 2010 at 8:37 PM, jim holtman wrote: >> I am not sure what you mean by eliminating a row.  Now if you want only one >> copy of ea

Re: [R] aggregating using 'with' function

2010-02-20 Thread jim holtman
I am not sure what you mean by eliminating a row. Now if you want only one copy of each 'id', and it is the first one, the you can use 'duplicated': > x <- with(datas, aggregate(list(r = r), by = list(id = id, mod1 = mod1),mean)) > x id mod1 r 1 11 0.980 2 41 0.640 3 7

Re: [R] aggregating using 'with' function

2010-02-20 Thread AC Del Re
Perfect! Thanks Jim. Do you know how I could then reduce the data even further? Specifically, reducing it to 1 id per row? In this dataset, id 1 would have one row eliminated. Assume the data is much larger and cannot be deleted by visual inspection and elimination one row at a time. Thank you,

Re: [R] aggregating using 'with' function

2010-02-20 Thread jim holtman
This seems to work fine (notice the missing 'c(...)'; why did you think you needed it); > with(datas, aggregate(list(r = r), by = list(id = id, mod1 = mod1),mean)) id mod1 r 1 11 0.980 2 41 0.640 3 71 0.490 4 101 0.180 5 12 0.295 6 52 0.490 7 8

[R] aggregating using 'with' function

2010-02-20 Thread AC Del Re
Hi All, I am interested in aggregating a data frame based on 2 categories--mean effect size (r) for each 'id's' 'mod1'. The 'with' function works well when aggregating on one category (e.g., based on 'id' below) but doesnt work if I try 2 categories. How can this be accomplished? # sample data i