[R] lapply assign to list

Henrique Dallazuanna wwwhsd at gmail.com
Wed Dec 2 20:23:45 CET 2009


Try this:

z1[] <- 1:3



On Wed, Dec 2, 2009 at 5:17 PM, Kenneth Roy Cabrera Torres
<krcabrer at une.net.co> wrote:
> Hi R users:
>
> I got an error that "l1" is not found.
>
> This is a sample code:
>
> f1<-function(i,l1){
>  print(l1[[i]])
>  l1[[i+1]]<<-i
>  return(i)
> }
>
> z1<-list(x=100,NULL,a=c(1,1))
> lapply(1:3,f1,l1=z1)
>
> My final goal is to update the value of
> each list component to use it in the following
> step.
>
> I see that print function founds l1[[1]],
> but the assign instruction not.
>
> Thank you for your help.
>
> Kenneth
>
> PD: R.Version()$version.string
> [1] "R version 2.10.0 Patched (2009-11-24 r50556)"
> on Ubuntu linux.
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O




More information about the R-help mailing list