[R] Decast

David Winsemius dwinsemius at comcast.net
Sat Nov 14 03:58:30 CET 2015


> On Nov 13, 2015, at 5:34 PM, Val <valkremk at gmail.com> wrote:
> 
> Hi all,
> I have a data frame called "df"  it's dimension is
> 
> dim(df)
> [1] 9540634       38
> 
>> From this data frame  the  variable *  df$X1 *has about 78, 000 unique
> values and  *df$region *has two classes.  I am trying to do  the following
> operation

It’s better to actually describe the operation so outside observers can advise whether the code is correct. My memory: dcast expects the row names to be on the LHS and the column names to be on the RHS:

> The goal is reshaping the variable from  long to wide
> 
> #############################
> library(reshape)
> library(reshape2)
> library(plyr)
> 
> sf1 <- ddply(df, df("df$X1","df$region"), summarise,
>                           N    = length(df$region))
> 

Generally R function that expect a formula do not expect the column names to be preceded by the dataframe name. You might try:

 xr  <- dcast(sf1, x1 ~  region,  value.var= "N”)


> 
> 
> With this huge data set it is taking more than 6 hours and I don't know
> when it is finishing.
> 
> I am sure the above syntax does not have any error because I tested with
> small data set and worked fine except the following message
> Aggregation function missing: defaulting to length
> 
> Is there an alternative way of doing this operation that may not take long
> hours.
> Thank you in advance
> 
> 	[[alternative HTML version deleted]]

Rhelp is a plain text mailing list.

— 
David.

> 
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA



More information about the R-help mailing list