[R] readBin into a data frame
Zhang Weiwu
zhangweiwu at realss.com
Thu Aug 1 10:36:10 CEST 2013
Hello. readBin is designed to read a batch of data with the same spec, e.g.
read 10000 floats into a vector. In practise I read into data frame, not
vector. For each data frame, I need to read a integer and a float.
for (i in 1:1000) {
dataframe$int[i] <- readBin(con, integer(), size=2)
dataframe$float[i] <- readBin(con, numeric(), size=4)
}
And I need to read 100 such data files, ending up with a for loop in a for
loop. Something feels wrong here, as it is being said if you use double-FOR
you are not speaking R.
What is the R way of doing this? I can think of writing the content of the
loop into a function, and vectorize it -- But, the result would be a list of
list, not exactly data-frame, and the list grows incrementally, which is
inefficient, since I know the size of my data frame at the outset. I am a
new learner, not speaking half of R vocabulary, kindly provide some hint
please:)
Best.
More information about the R-help
mailing list