[R] R for loop
Jeff Newmiller
jdnewmil at dcn.davis.CA.us
Sat Nov 16 02:34:36 CET 2013
You seem to have a problem with your Mindreader skills today, David!
---------------------------------------------------------------------------
Jeff Newmiller The ..... ..... Go Live...
DCN:<jdnewmil at dcn.davis.ca.us> Basics: ##.#. ##.#. Live Go...
Live: OO#.. Dead: OO#.. Playing
Research Engineer (Solar/Batteries O.O#. #.O#. with
/Software/Embedded Controllers) .OO#. .OO#. rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.
David Carlson <dcarlson at tamu.edu> wrote:
>I would be easier to respond if we had some idea what
>Mindreader_2012_vars is, data.frame, list, matrix?
>
>Give us a small, reproducible version of what you are trying to
>accomplish.
>
>-------------------------------------
>David L Carlson
>Department of Anthropology
>Texas A&M University
>College Station, TX 77840-4352
>
>-----Original Message-----
>From: r-help-bounces at r-project.org
>[mailto:r-help-bounces at r-project.org] On Behalf Of matira
>Sent: Friday, November 15, 2013 7:23 AM
>To: r-help at r-project.org
>Subject: [R] R for loop
>
>Hi
>I'm quite new to R and I am having trouble with this code:
>
>names(Mindreader_2012_vars)
>varlist<-names(Mindreader_2012_vars)
>for (i in 688:696) {
> for (j in 673:685) {
>
>assign(paste("Uk_Cluster_",i-687,sep=""),cbind(get(varlist[j],po
>s=Mindreader_2012_vars)[get(varlist[i],
>pos=Mindreader_2012_vars)>0]))
>}
>}
>
>I want this code to output 9 matrixes (which are the variables
>'i' is
>getting) which have 13 columns (one for each of the variables
>that 'j' is
>getting.
>At the moment I get 9 matrixes with only 1 column. I guess the
>issue is the
>way I am nesting the loops but i can't work out how to make it
>take all the
>values of 'j' in each matrix.
>
>Thanks
>
>
>
>--
>View this message in context:
>http://r.789695.n4.nabble.com/R-for-loop-tp4680515.html
>Sent from the R help mailing list archive at Nabble.com.
>
>______________________________________________
>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.
>
>______________________________________________
>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.
More information about the R-help
mailing list