Re: [R] Creating new columns inside a loop

From: David L. Van Brunt, Ph.D. <dlvanbrunt_at_gmail.com>
Date: Fri 12 Aug 2005 - 01:38:16 EST

Ok, here's an english pseudo coded version of what I'd like to do...

10 columns of (somedata)
names(somedata): C1 C2 C3 C4 C5
Loop through each column
FOR ColName = C1 through C5
Compute a new column, named "ColNameA" = some result for each row Compute another new Column named ColNameB" = some other result for each row NEXTColName

Desired Result:
Names(somedata): C1 C1A C1B C2 C2A C2B C3 C3A C3B C4 C4A C4B C5 C5A C5B

So, basically, my question is how to both address and assign the names of the variables rather than the values of the variables while coding my loop. I hope that's clearer... kind of hard to explain!

On 10 Aug 2005 21:55:01 +0200, Peter Dalgaard <p.dalgaard@biostat.ku.dk> wrote:
>
> "David L. Van Brunt, Ph.D." <dlvanbrunt@gmail.com> writes:
>
> > Ok, I know R isn't an optimal environment for looping (or so I've heard)
> but
> > I have a need to loop through columns of data and create new columns of
> data
> > based on calculations within rows...
> >
> > I'm sure there's a help file, but I'm not sure what search terms to use
> to
> > find it! The problem is that these new columns need to have names that I
> can
> > later access... Like NewVar1, NewVar2, etc....
> >
> > In php I'd call this "indirection" but I'm not sure what to call it in R
> so
> > that I can find instructions on how to create, name, and address the
> values
> > stored this way...
> >
> > any gentle nudges in the right direction would be greatly appreciated!
>
> A little more information about what you're actually trying to do and
> I'm sure someone will give you a nudge with a sledgehammer...
>
> At present, your description is just that little bit too nebulous.
>
> --
> O__ ---- Peter Dalgaard ุster Farimagsgade 5, Entr.B
> c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
> (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
> ~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
>

-- 
---------------------------------------
David L. Van Brunt, Ph.D.
mailto:dlvanbrunt@gmail.com

	[[alternative HTML version deleted]]


______________________________________________ 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

Received on Fri Aug 12 01:42:44 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:47 EST