[R] Newbie: Simple loops: complex troubles

projection83 mkurowski at gmail.com
Wed Apr 4 05:55:08 CEST 2007


I am used to java (well, i dont remember it really well, but anyway)

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?


All in all, I dont know if i am going about this loop stuff a reaaaaly round
about way - Any help would make me much less loopy:Pthanks 



-- 
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.



More information about the R-help mailing list