Quantcast
Channel: Adding elements to a list in for loop in R - Stack Overflow
Browsing latest articles
Browse All 2 View Live

Answer by Rich Scriven for Adding elements to a list in for loop in R

It seems like you're looking for a construct like the following:N <- 3x <- list()for(i in 1:N) { Ps <- i ## where i is whatever your Ps is x[[paste0("element", i)]] <- Ps}x# $element1# [1]...

View Article



Adding elements to a list in for loop in R

I'm trying to add elements to a list in a for loop. How can I set the field name?L <- list() for(i in 1:N) { # Create object Ps... string <- paste("element", i, sep="") L$get(string) <- Ps }I...

View Article
Browsing latest articles
Browse All 2 View Live


Latest Images