Re: [R] Problems reshaping data with cast()

From: hadley wickham <h.wickham_at_gmail.com>
Date: Thu, 7 Feb 2008 08:21:04 -0600

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/

______________________________________________
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.
Received on Thu 07 Feb 2008 - 14:24:20 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 07 Feb 2008 - 15:30:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive