[R] Loop to fill in array skips over certain columns
poastpd at umich.edu
poastpd at umich.edu
Fri Sep 12 15:36:09 CEST 2008
Hello,
Below is a simple loop that should place a 3 in the first row of each
column in the array "List".
iterations<-3
tweaksize<-0.00
ii <-1
List=array(-1000, dim=c(iterations,11))
colnames(List) <- c("orig", "0.05", "0.10",
"0.15","0.20","0.25","0.30","0.35","0.40","0.45","0.50")
Entry=3
while (tweaksize<=0.5) {
if (tweaksize==0.00) coll = 1
if (tweaksize==0.05) coll = 2
if (tweaksize==0.10) coll = 3
if (tweaksize==0.15) coll = 4
if (tweaksize==0.20) coll = 5
if (tweaksize==0.25) coll = 6
if (tweaksize==0.30) coll = 7
if (tweaksize==0.35) coll = 8
if (tweaksize==0.40) coll = 9
if (tweaksize==0.45) coll = 10
if (tweaksize==0.50) coll = 11
List[ii,coll]=Entry
tweaksize = tweaksize + 0.05
}
List
However, if I run the loop, R skips the 4th column (0.15), 9th column
(0.40), 10th column (0.45), and eleventh column (0.50). Below is the
output:
orig 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50
[1,] 3 3 3 -1000 3 3 3 3 -1000 -1000 -1000
[2,] -1000 -1000 -1000 -1000 -1000 -1000 -1000 -1000 -1000 -1000 -1000
[3,] -1000 -1000 -1000 -1000 -1000 -1000 -1000 -1000 -1000 -1000 -1000
Can anyone please suggest a reason why R is skipping these four
columns? Any help will be greatly appreciated.
Thank you,
Paul
More information about the R-help
mailing list