convert raw data file to RData file

I am trying to make a RData file from a raw numeric space deliminated text file, ie

11 33 55
22 33 45
25 78 00 
44 87 99 ....

I have another R script which needs to load this new RData file and perform linear regression with the data using mapreduce (rhipe). Thus when i save this RObject I need to read it back this way:

data <- strsplit(unlist(map.values)," ")

#so that I can run regression like:
y<- unlist(lapply(data,"[[",1))
x1<-unlist(lapply(data,"[[",2))
x2<-unlist(lapply(data,"[[",3))
lm(y~x1+x2)

I have tried many ways to save my data into the RData object, including table, list and as.character, but non of the succeed so that i can read it using my above method. How can I save my original file so that I can read it in the way I have above? Thank you.

(ps. i cannot use load / read.table functions since i am reading from a HDFS file inside the mapper)


If I understand you correctly, you want your stored object to be a bunch of strings of the form "number - space - number" . In that case, use sprintf

foo <- sprintf('%d %d %d',my_data[1,])

as an example of creating the first row. Run a loop or *apply to build the entire array. Save that character string array to an RData file. This should at least be close to what you want.
Note: I suppose it's futile to suggest improving the far-end code which does the data sorting and regressions?

链接地址: http://www.djcxy.com/p/6528.html

上一篇: Excel导入后清理混合十进制分隔符(gsub也许?)

下一篇: 将原始数据文件转换为RData文件