Re: [R] Error with lapply

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Thu, 20 Nov 2008 11:57:07 -0500

lapply already passes the first arg to fn and by specifying the i (which is undefined -- its only defined within fn) it would be trying to to pass a second arg to fn yet fn takes only takes one arg. Try these:

lapply(1:4, fn)
lapply(1:4, "^", 2)

On Thu, Nov 20, 2008 at 11:31 AM, megh <megh700004_at_yahoo.com> wrote:
>
> I have written following codes, with intention to get a list with values
> 1,2,9,16 :
>
> fn <- function(i) return(i^2)
> lapply(1:4, fn, i)

>
> However I got following error :
> Error in FUN(1:4[[1L]], ...) : unused argument(s) (1)
>
> Can anyone please tell me what will be the correct code here?
>
> Regards,
>
>
> --
> View this message in context: http://www.nabble.com/Error-with-lapply-tp20605066p20605066.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.
>



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 20 Nov 2008 - 17:06:15 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 20 Nov 2008 - 17:30:27 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