0

I am trying to make a RData file from a raw numeric space deliminated text file, i.e

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)

cs_newbie
  • 1,959
  • 1
  • 15
  • 16

1 Answers1

0

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?

Carl Witthoft
  • 20,573
  • 9
  • 43
  • 73
  • when i am reading back my .RData file using RHipe, i am getting something like: filename ï¿ t6�}������HN�D�i�TFl?�,����5����z��MG6BU����fQ3�Û����ʴJ�@�Ó�l���n'���d�A�TT�\��!������u�[N�#`X1pA what am i missing to decode this? – cs_newbie Feb 27 '13 at 20:23