[R] Regrouping dataframe

David Winsemius dwinsemius at comcast.net
Thu Nov 8 22:03:56 CET 2012


On Nov 8, 2012, at 9:51 AM, Geophagus wrote:

> Hi @ all,
> I hope for some help of you.
> I have a dataframe and I want to regroup it.
> examp4.csv <http://r.789695.n4.nabble.com/file/n4648927/examp4.csv>  

Sigh. Please expalin why you posted a link to a "csv file" that had no commas.

> 
> I need the arguments of "VAL" as table heads and the "TYPE " only in
> individual expression.
> The result should look like in the example pic.
> 
> exp4.png <http://r.789695.n4.nabble.com/file/n4648927/exp4.png>  
> 
> I think reshape can do it?

Perhaps, but since you only have one value per cross-category, why not:

xtabs(AMOUNT ~ TYPE+VAL, data=t1)

OR:

tapply(t1$AMOUNT, list(t1$TYPE, t1$VAL), c)


-- 

David Winsemius, MD
Alameda, CA, USA




More information about the R-help mailing list