# [R] Newbie: Simple loops: complex troubles

From: projection83 <mkurowski_at_gmail.com>
Date: Wed 04 Apr 2007 - 03:55:08 GMT

I have having a really difficult time making simple loops to work. I got the following to work:

```         ##

##Creates objects Ux1, Ux2, Ux2 etc. that  all contain n numbers in a

random distribution

##
m<-c(m1,m2,m3,m4,m5,m6,m7,m8,m9,m10)#these are defined as numbers (means)
v<-c(v1,v2,v3,v4,v5,v6,v7,v8,v9,v10)#these are defined as numbers
(variances)
n<-50
for(k in 1:g)
{
assign( paste("Ux", k, sep=""), rnorm( n  ,
```
assign(paste("m",1,sep=""),m[k]) , assign(paste("m",1,sep=""),v[k]) ) )

}

The above seems like a lot of work for such a simple feat, no?

Also, I CANNot get the following to work in a loop manor:

```        Ux1i<-as.integer(Ux1)
Ux2i<-as.integer(Ux2)
Ux3i<-as.integer(Ux3)

```

or

```	Sx1<-sort(Ux1i)
Sx2<-sort(Ux2i)
Sx3<-sort(Ux3i)

```

Maybe I am just not using matrixes enough? but even that seems quite a lot more complex than calling x<-matrix() then grabbing values by x[j][k]...(java style if i remember correctly). the matrix help in R dosnt make much sense to me. And also i am not sure why numeric() dosnt make you define length before you use it, yet matrix() does. Is there some other funciton that i should be using to make length not an issue?

```--
View this message in context: http://www.nabble.com/Newbie%3A-Simple-loops%3A-complex-troubles-tf3523751.html#a9830574
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
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
and provide commented, minimal, self-contained, reproducible code.
```
Received on Wed Apr 04 13:58:12 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 04 Apr 2007 - 12:31:00 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.