Hello,
I'm trying to read a file that has ascci data in it. The format of the
data
is in this order: test_number(integer) 4 double readings. Simple,ok, but for
life of me I can't get R to put it into the internal format I need. What I
want
to do is to make an array called dat and dim it 10000 rows by 5 columns.
That seems simple enough, I start out by:
dat <- array(0,dim=c(10000,5)) this looks ok.
The next thing I did was to scan in the data.
dat
<-scan("mydata-file",what=array(""),sep="\n").
I get the data into the dat array but its looks like a string.
ie "1000 34.5 34.7 35 35.6".
what I want is to make each of these data point go into
the appropriate array index ie:
dat[1][1] dat[1][2] dat[1][3] dat[1][4] dat[1][5]
1000 34.5 34.7 35 35.6
Any help would be greatly appreciated.
Thank you
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
https://stat.ethz.ch/pipermail/r-help/attachments/20001112/f981c178/attachment.html
tmed <tmed at pacbell.net> writes:> Hello, > > I'm trying to read a file that has ascci data in it. The format of > the data > is in this order: test_number(integer) 4 double readings. Simple,ok, but > for=20 > life of me I can't get R to put it into the internal format I need. What > I want > to do is to make an array called dat and dim it 10000 rows by 5 columns. > That seems simple enough, I start out by: > > dat <- array(0,dim=3Dc(10000,5)) this looks ok.=20 > The next thing I did was to scan in the data. > dat <-scan("mydata-file",what=3Darray(""),sep=3D"\n"). > I get the data into the dat array but its looks like a string. > ie "1000 34.5 34.7 35 35.6". > what I want is to make each of these data point go into=20 > the appropriate array index ie: > dat[1][1] dat[1][2] dat[1][3] dat[1][4] dat[1][5] > 1000 34.5 34.7 35 35.6 > > Any help would be greatly appreciated.matrix(scan("mydata-file"), ncol=5, byrow=TRUE) or do.call("cbind", scan("mydata-file", what=rep(0,5))) or as.matrix(read.table("mydata-file")) should all work ("should" being code for "I didn't actually try"). I'd expect the middle one to be the most efficient, but who knows. BTW: Accessing an element of a matrix is dat[1,1] in R, not dat[1][1] as in C.> ------=_NextPart_000_0005_01C04CA5.30664F20 > Content-Type: text/html; > charset="iso-8859-1" > Content-Transfer-Encoding: quoted-printableUm, please try to avoid that stuff. It looks bad in some peoples mailers, and I think it also messes with the list digests. -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Hello,
Yesterday I asked a question about how to read data from a file
that had test numbers in the first column followed by 4 readings. I received
three responses to my question with in an hour. Thanks to all who responded.
After trying out your responses - which seem to work. I noticed that some of
the data had only one or two reading after the test number.
My next question: what's the command to fill a matrix with an unknown
value of column data. The nice people who responded to me yesterday used
matrix(scan("data.file"),rcol=5, byrow=TRUE). I would have to imagine
the
solution is some variation on this theme. I tried several last night
myself, but
with no success. I hope that you will bear with me though this leaning curve.
I HAVE tried to read the documentation, but there is so much information that
it's some what overwhelming. I'm sure all of you know how important it
is to be able to succeed in using a new tool to prevent being frustrated and
giving up prematurely. I am truly in awe over this tool, its power is
amazing.
I hope you will bear with me as I continue in the mastery of this incredible
tool.
Thanks for all your help,
Tom Likins
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._