[R] nested for loop

Sherri Heck sheck at ucar.edu
Wed Jul 18 19:45:06 CEST 2007


I am new to programming and R.  I am reading the manual and R books by Dalgaard and Veranzo to help answer my questions but I am unable to figure out the following:

I have a data file that contains 1080 data points. Here's a snippet of the file:

[241]  0.3603704000  0.1640741000  0.2912963000   NA  0.0159259300  0.0474074100            

I would like to break the file up into 30 consecutive data point segments and then write each segment into a separate data file.  This is one version of code that I've tried.  

mons = c(1:12)

data = scan(paste("C:/R/NWR.txt"))
for (mon in mons)  {
 for (i in c(1:30)) {
  for (j in data)    {

write((data),paste(mon,'NWR dc_dt_zi ppm meters per sec.txt',sep=''),ncol=1)   


I think I'm really close, but no cigar.  Thanks in advance for any help-

Graduate Research Assistant
University of Colorado, Boulder

More information about the R-help mailing list