I am trying to create distinct variable names of the form Corr1, Corr2, etc. so that I can run cbind(nurkle,Corrk) When I run the code below, I receive the following error message Error in paste(Corr,k) <- out[[k]]$acf: could not find the function paste<- How can I create a variable name with a sequential number than can be used as the receiving end of my assignment statement? nurkle <- out[[1]]$acf for (k in 2:10){ paste(Corr,k) <- out[[k]]$acf nurkle<- cbind(nurkle,Corrk) } Thank you, John [[alternative HTML version deleted]]
Hello, Replace the for loop by a lapply loop and assign the names after, with sprintf("Corr%d", 1:10) Is out a data.frame? Can you post dput(head(out))? Hope this helps, Rui Barradas ?s 18:33 de 14/05/2022, Sorkin, John escreveu:> I am trying to create distinct variable names of the form Corr1, Corr2, etc. so that I can run cbind(nurkle,Corrk) > When I run the code below, I receive the following error message > Error in paste(Corr,k) <- out[[k]]$acf: could not find the function paste<- > How can I create a variable name with a sequential number than can be used as the receiving end of my assignment statement? > > > nurkle <- out[[1]]$acf > for (k in 2:10){ > paste(Corr,k) <- out[[k]]$acf > nurkle<- cbind(nurkle,Corrk) > } > > Thank you, > John > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
?assign as in assign(paste0('Corr',k), out[[k]]$acf) ## note 'Corr' must be a string! However, IMO you would do better keeping your results in a list using lapply(), as overpopulating your workspace with 'suggestive' names is error prone. Bert On Sat, May 14, 2022 at 10:34 AM Sorkin, John <jsorkin at som.umaryland.edu> wrote:> > I am trying to create distinct variable names of the form Corr1, Corr2, etc. so that I can run cbind(nurkle,Corrk) > When I run the code below, I receive the following error message > Error in paste(Corr,k) <- out[[k]]$acf: could not find the function paste<- > How can I create a variable name with a sequential number than can be used as the receiving end of my assignment statement? > > > nurkle <- out[[1]]$acf > for (k in 2:10){ > paste(Corr,k) <- out[[k]]$acf > nurkle<- cbind(nurkle,Corrk) > } > > Thank you, > John > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.