Re: [R] lapply?

From: Uwe Ligges <ligges_at_statistik.uni-dortmund.de>
Date: Sun 20 Aug 2006 - 00:31:25 EST

eugene dalt wrote:
> Hi folks,
>
> I would like to know if the following loop can be
> rewritten with lapply
>
>
> list1 <- as.list(0)
>
> testv <- c(4,6,7,8)
>
> for( i in 1:4){
>
> list1[[i]] <- rep(5,testv[i])
>
> }

Please do not cross-post!

lapply(testv, rep, x = 5)

Uwe Ligges

> Thanks in Advance. - Eugene
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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@stat.math.ethz.ch 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 Sun Aug 20 01:51:02 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sun 20 Aug 2006 - 04:19:32 EST.

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