[R] Data Frame Manipulations
Petr Pikal
petr.pikal at precheza.cz
Wed Dec 1 13:06:49 CET 2004
Hi Michael
On 1 Dec 2004 at 11:50, michael watson (IAH-C) wrote:
> Hi
>
> I have used merge() to merge two data frames, very much like
> performing a SQL join. Now I want to do a few different SQL-style
> things and I wondered if there were functions to do it...
>
> Is there a "group by" style function? For example if I merge() two
> data frames and end up with multiple rows for each "id", and want to
> take the average of the values of a particular column? I know I can
> probably put something together using merge() and by() and then
> munging the results together myself, but is there something in R to
> perform this automatically?
aggregate, by, *apply but AFAIK only after merge
>
> The second thing I'd like to do is like a cross-tab query; that is
> when after a merge() I end up with multiple rows for a particular
> "id", and want to cross-tab the data so that the multiple values
> become columns and I end up with one row for each "id" again e.g.
reshape in base or reShape in Hmisc is probably what you need
Cheers
Petr
>
> ID Val
> 1 5
> 1 10
> 2 15
> 2 20
>
> Becomes
>
> ID Val1 Val2
> 1 5 10
> 2 15 20
>
> Thanks in advance!
>
> Mick
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list