Skip to content

listing array after loop

4 messages · uday, Petr Savicky, R. Michael Weylandt

#
I want to create r object from my data set.
I have several data files  and I would like to read individual parameter
from file and save all 10 files parameter in a single array 
e.g 
setwd("/temp/")
file_s <- list.files(path = ".", pattern = "0b.was", all.files = FALSE,
                    full.names = FALSE, recursive = FALSE, ignore.case =
FALSE)
  lat       <- NULL
  lon      <- NULL
  ch4        <- NULL
for ( i in 1:10) { 
          data            <-   read.table(file_s[i],header=TRUE,skip=55 ) 
          lat[i]           =     data[,7] # latitude
          temp.lon  = data[,8] # longitude
# the longitude data is in 360 degree format need to convert to -180 to 180
          lon[i]         =  ((temp.lon+180) %% 360 ) - 180 
          ch4[i]        =  data[,45] # ch4
}

save (lat,lon,ch4, file="myData.RData"")

but some how it does not work . 

How to list all data in single array after loop .




--
View this message in context: http://r.789695.n4.nabble.com/listing-array-after-loop-tp4418081p4418081.html
Sent from the R help mailing list archive at Nabble.com.
#
On Fri, Feb 24, 2012 at 09:48:16AM -0800, uday wrote:
Hi.

If you get an error message, please, send it. If you get a
result, but it differs from what you expect, explain, what
is wrong. At the first glance, i do not see anything
suspicious. However, i do not know, what is the contents
of the files file_s[i] and whether the number of file
names in file_s is at least 10.

Petr Savicky.
#
The following error I got 

Warning messages:
1: In sci.lat[i] = data[, 7] :
  number of items to replace is not a multiple of replacement length
2: In sci.lon[i] = ((temp.lon + 180)%%360) - 180 :
  number of items to replace is not a multiple of replacement length
3: In sci.ch4[i] = data[, 45] :
  number of items to replace is not a multiple of replacement length
4: In sci.lat[i] = data[, 7] :
  number of items to replace is not a multiple of replacement length
5: In sci.lon[i] = ((temp.lon + 180)%%360) - 180 :
  number of items to replace is not a multiple of replacement length
6: In sci.ch4[i] = data[, 45] :
  number of items to replace is not a multiple of replacement length
Error in gzfile(file, "wb") : cannot open the connection
In addition: Warning message:
In gzfile(file, "wb") :
  cannot open compressed file 'myData.RData', probable reason 'Permission
denied

--
View this message in context: http://r.789695.n4.nabble.com/listing-array-after-loop-tp4418081p4418752.html
Sent from the R help mailing list archive at Nabble.com.
#
This sure sounds like you need to read the advice I gave you on the
other thread where you asked the same questions...

Michael
On Fri, Feb 24, 2012 at 5:04 PM, uday <uday_143_4u at hotmail.com> wrote: