I have 100 data files, which contains very huge data sets of location details ( e.g latitude, longitude, time, temp) Now I would like to save the all data of these 100 files in r object, so I can reload data any time. * Every file has different length of data latitude <- NULL longitude <- NULL time <- NULL temp <- NULL for ( i in 1:100) { data<- read.table(file_s[i],header=TRUE,skip=55 ) latitude [i] <- data[,6] longitude[i] <- data[,7] time[i] <- data[,8] temp[i ] <- data [,9] } save(latitude=latitude,longitude=longitude, time=time,temp=temp, file="data.RData") but it does not work. I am new in R and I got stuck here. Cheers Uday I am beginner in R and I got stuck here -- View this message in context: http://r.789695.n4.nabble.com/saving-all-data-in-r-object-tp4413092p4413092.html Sent from the R help mailing list archive at Nabble.com.
It looks like it works. (I ran your code leaving out the inner non-reproducible loop and just saving the NULL objects with your syntax) What is the error you are getting? Michael On Thu, Feb 23, 2012 at 3:01 AM, uday <uday_143_4u at hotmail.com> wrote:> > I have 100 data files, which contains very huge data sets of location > details ( e.g latitude, longitude, time, temp) > Now I would like to save the all data of these 100 files in r object, so I > can reload data any time. > > * Every file has different length of data > > latitude ? ? ?<- NULL > longitude ?<- NULL > time ? ? ? ? ? ?<- NULL > temp ? ? ? ? ?<- NULL > > for ( i in 1:100) { > > data<- read.table(file_s[i],header=TRUE,skip=55 ) > latitude [i] ? ? ?<- data[,6] > longitude[i] ? <- data[,7] > time[i] ? ? ? ? ? ?<- data[,8] > temp[i ] ? ? ? ? <- data [,9] > > } > save(latitude=latitude,longitude=longitude, time=time,temp=temp, > file="data.RData") > but it does not work. > > I am new in R and I got stuck here. > > Cheers > Uday > > > > > > I am beginner in R and I got stuck here > > -- > View this message in context: http://r.789695.n4.nabble.com/saving-all-data-in-r-object-tp4413092p4413092.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.
Michael , the first error which I got is "number of items to replace is not a multiple of replacement length" sorry last time it did not copied whole thing -- View this message in context: http://r.789695.n4.nabble.com/saving-all-data-in-r-object-tp4413092p4414058.html Sent from the R help mailing list archive at Nabble.com.
Hi Uday, You could try to include 'write.table' in your loop and use paste to save every file separately like this: for ( i in 1:100) { data<- read.table(file_s[i],header=TRUE,skip=55 ) latitude [i] <- data[,6] longitude[i] <- data[,7] time[i] <- data[,8] temp[i ] <- data [,9] write.table (lattitude, file=paste("lattitude", i, sep="_") ) write.table (longitude, file=paste("longitude", i, sep="_")) write.table (time, file=paste("time", i, sep="_")) write.table (temp, file=paste("temp", i, sep="_")) } I think that should work. Cheers, Iris -- View this message in context: http://r.789695.n4.nabble.com/saving-all-data-in-r-object-tp4413092p4416896.html Sent from the R help mailing list archive at Nabble.com.
Hi Iris, thanks for reply but this solution does not work Uday -- View this message in context: http://r.789695.n4.nabble.com/saving-all-data-in-r-object-tp4413092p4417933.html Sent from the R help mailing list archive at Nabble.com.