I think this does what you are looking for:
dta - data.frame(q1_1=rep(1,5),q1_2=rep(2,5),q2_1=rep(3,5),q2_2=rep(4,5))
for (i in 1:2) {
e1 - paste(q,i,_1 + q,i,_2 * 2,sep=)
assign(paste(q,i,sep=),with(dta,eval(parse(text=e1
}
On 25/09/06, Peter Wolkerstorfer - CURE [EMAIL
- Original Message -
From: David Barron [EMAIL PROTECTED]
To: Peter Wolkerstorfer - CURE [EMAIL PROTECTED]; r-help
r-help@stat.math.ethz.ch
Sent: Monday, September 25, 2006 3:33 PM
Subject: Re: [R] Beginner Loop Question with dynamic variable names
I think this does what you
Is this what you had in mind?
j-data.frame(q1=rnorm(10),q2=rnorm(10))
j
q1 q2
1 -0.9189618 -0.2832102
2 0.9394316 1.1345975
3 -0.6388848 0.6850255
4 0.4938245 -0.5825715
5 -1.2885257 -0.2654023
6 -0.5278295 0.2382791
7 0.6517268 0.8923375
8 0.4124178
On Sat, 2006-08-26 at 13:06 -0400, Wensui Liu wrote:
Dear Lister,
If I have a list of number, say x-c(0.1, 0.5, 0.6...), how to use a for()
to loop through each number in x one by one?
Thank you so much!
wensui
Two options:
x - c(0.1, 0.5, 0.6)
for (i in x) {print (i)}
[1] 0.1
[1]
let us know what you want to do because the beauty of R is that, in many
cases, you may not have to loop.
- Original Message -
From: Wensui Liu [EMAIL PROTECTED]
To: r-help@stat.math.ethz.ch
Sent: Saturday, August 26, 2006 1:06 PM
Subject: [R] for() loop question
Dear Lister,
If I
On Fri, 27 Feb 2004 13:09:40 -0800 (PST) Susan Lin wrote:
I want to get three .gif image files test.1.gif,
test.2.gif, test.3.gif by using a loop. The code I
tried is like this:
x=c(0, 1, 2, 3, 4)
y=c(1, 2, 3, 4)
for(i in 1:3)
{
x11()
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of Susan Lin
Sent: Saturday, February 28, 2004 10:10 AM
To: [EMAIL PROTECTED]
Subject: [R] a loop question
I want to get three .gif image files test.1.gif,
test.2.gif, test.3.gif by using a loop. The