Skip to content
Back to formatted view

Raw Message

Message-ID: <4EA13128.8020707@statistik.tu-dortmund.de>
Date: 2011-10-21T08:45:28Z
From: Uwe Ligges
Subject: 'Apply' giving me errors
In-Reply-To: <1319155776857-3923880.post@n4.nabble.com>

On 21.10.2011 02:09, kickout wrote:
> So i have a simple function:
>
> bmass=function(y){
> weight=y$WT*y$MSTR
> return(bio)
> }
>
> And want to apply to a whole bunch of rows in my data.frame:
>
> final1=apply(final,1,yldbu)
>
>
> BUT...recieve the following error:
> "Error in y$WT : $ operator is invalid for atomic vectors"
>
>
> However when i try:
>> final[1,]$WT*final[1,]$MSTR
> [1] 156.3
>
>
> It gives me the correct answer....what is apply not liking in my code?

Since apply passes the rows as vectors into your function, not as a 
data.frame of 1 row.

I woder why you need apply() at all, since
  final$WT * final$MSTR
should do.

Uwe Ligges









>
> Thanks
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Apply-giving-me-errors-tp3923880p3923880.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.