[R] Problems reshaping data with cast()

hadley wickham h.wickham at gmail.com
Thu Feb 7 15:21:04 CET 2008


Hi Neil,

I think your cast statement is wrong.  You have

cast(norm.all.melted.height, Sample.Name + SNP + Pool ~ value, sum)

but I think you want

cast(norm.all.melted.height, Sample.Name + SNP + Pool ~ ., sum)

i.e. value never appears in the cast formula.

Hadley

On Feb 7, 2008 7:11 AM, Neil Shephard <nshephard at gmail.com> wrote:
> Hi,
>
> I'm trying to cast() some data, but keep on getting the following error...
>
> > norm.all.melted.height <- transform(all.melted.height,
> +                                     norm.height = value / ave(value,
> SNP, Pool, FUN = max)
> +                                     )
> Warning messages:
> 1: In FUN(X[[147L]], ...) :
>   no non-missing arguments to max; returning -Inf
> 2: In FUN(X[[147L]], ...) :
>   no non-missing arguments to max; returning -Inf
> 3: In FUN(X[[147L]], ...) :
>   no non-missing arguments to max; returning -Inf
> > norm.all.melted.height <- subset(norm.all.melted.height, select=c("Sample.Name", "SNP", "Pool", "variable", "norm.height"))
> > names(norm.all.melted.height) <- c("Sample.Name", "SNP", "Pool", "variable", "value")
> >
> > ## Now reshape the data
> > normalised <- cast(norm.all.melted.height, Sample.Name + SNP + Pool ~ value, sum)
> Error in rep.int(rep.int(seq_len(nx), rep.int(rep.fac, nx)), orep) :
>   negative length vectors are not allowed
>
> Is the error thats occuring with cast() likely to be caused by the
> previous warnings?
>
> As far as I can work out rep.int() is called to expand the data based
> on the grouping specified (in this case the left hand portion of the
> cast formula, i.e.  Sample.Name + SNP + Pool), but how would there be
> a negative index in this data?  I had previously melted the data into
> this format.
>
> Apologies for not providing a reproducible example, I suspect the
> problem lies within the data structure I'm using.
>
> Thanks for reading this question,
>
> Neil
>
> --
> Email - nshephard at gmail.com / n.shephard at sheffield.ac.uk
> Photos - http://www.flickr.com/photos/slackline/
>
> ______________________________________________
> R-help at r-project.org mailing list
> 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.
>



-- 
http://had.co.nz/



More information about the R-help mailing list