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
> 
> ______________________________________________
> [email protected] 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.

______________________________________________
[email protected] 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.

Reply via email to