RE: [R] data frame output in loops

From: Francisco J. Zagmutt <gerifalte28_at_hotmail.com>
Date: Sat 07 May 2005 - 06:02:05 EST


No need for computer-intensive loops. Try the following:

a <- data.frame(x = c(1,2,3,4), y = c(1,2,1,2))
xx=data.frame(x.1=a[,1],x.2=2*a[,1])
yy=data.frame(y.1=a[,2],y.2=2*a[,2])

Cheers

Francisco

>From: "Apoian, Zack" <Zack.Apoian@sac.com>
>To: <r-help@stat.math.ethz.ch>
>Subject: [R] data frame output in loops
>Date: Fri, 6 May 2005 14:56:21 -0400
>
>I know this is very basic--I'm wondering if there is a way to write data
>frames as outputs from a loop.
>In other words, take this simple example:
>
> > a <- data.frame(x = c(1,2,3,4), y = c(1,2,1,2))
>
>Given a, how would you write a loop that creates two data frames, x and y,
>where the first column is a column of a and the second column is two times
>the first column, or:
>
> > x
> x.1 x.2
>1 1 2
>2 2 4
>3 3 6
>4 4 8
>
>
>and
>
> > y
> y.1 y.2
>1 1 2
>2 2 4
>3 1 2
>4 2 4
>
>
>
>
>DISCLAIMER: This e-mail message and any attachments are inte...{{dropped}}
>
>______________________________________________
>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



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 Sat May 07 06:33:24 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:37 EST