[R] Generate the next column from previous column

Steven Wolf wolfste4 at msu.edu
Fri Jun 24 03:11:12 CEST 2011


Basically you need to set up a recursive relationship.  I'd do this with a
2D array:

G = numeric(6*N)
dim(G) = c(6,N)
G[,1] = c(1,rep(0,5))
for (i in 2:N){G[,i]=G[,i-1]+5* c(1,rep(0,5))}

HTH,
-Steve

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of Mkkl
Sent: Thursday, June 23, 2011 5:17 PM
To: r-help at r-project.org
Subject: [R] Generate the next column from previous column

Hi, I'm quite new to R and are stuck with the following problem.

Lets say I have a column consisting of a 1 and the rest zero's, called G0.
G0 <- c(1,rep(0,5))

Now what I would like to do is to generate G1 from G0, and G2 from G1 etc...
Just for the simplicity, let's say I need the first entry of the column to
be increased by 5 each time.

How could I do this?
Thanks already!

Kind regards,

Michael


--
View this message in context:
http://r.789695.n4.nabble.com/Generate-the-next-column-from-previous-column-
tp3621051p3621051.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org 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.



More information about the R-help mailing list