[R] trouble in (scan -- read.table)
Jonathan Baron
baron at cattell.psych.upenn.edu
Sun May 5 22:41:16 CEST 2002
On 05/05/02 16:21, hkimscil wrote:
>Hello all -
>I must be wrong in using commands...
Yes. scan() reads data horizontally, but matrix() fills up one
column at a time starting at the left. You can change the
behavior of matrix() with byrow=T.
>The below is my data (test.data). Its size is 10 X 15.
>1 1 1 1 1 1 0 1 1 1 1 1 0 1 0
>1 1 1 0 0 1 0 0 0 1 0 0 1 1 1
>1 1 1 0 0 1 0 1 0 0 0 1 1 1 1
>0 0 0 0 1 1 0 0 0 1 1 0 0 1 1
>1 1 1 1 0 1 0 1 0 1 0 0 0 1 1
>0 1 0 0 0 1 0 0 0 1 1 0 1 0 0
>1 1 0 1 0 1 1 1 0 0 1 0 1 0 0
>1 1 0 1 0 1 1 1 0 1 0 1 1 0 0
>0 1 1 1 1 1 1 0 1 1 0 1 1 0 0
>1 1 0 0 0 1 0 0 1 0 1 1 1 0 0
>
>I am importing the data into a matrix test1, using scan.
>> test1<-matrix(scan("test.data"),nrow=10,ncol=15)
This should work if you say
test1<-matrix(scan("test.data"),nrow=10,ncol=15,byrow=T)
>Then, I do the same thing with read.table
>> test2<-as.matrix(read.table("test.data"))
>
>Now, test1 and test2 are different (test2 is the correct one).
>
>test1:
>1 1 1 1 0 1 1 0 1 1 1 1 0 0 1
>1 1 0 1 1 0 1 0 0 1 0 1 1 1 0
>1 0 0 1 1 0 1 0 0 0 1 1 1 1 0
>1 1 0 0 1 0 1 1 0 1 0 0 1 0 1
>1 0 1 0 1 1 0 1 1 0 0 1 1 0 0
>1 1 0 1 0 1 1 0 1 1 1 0 1 1 1
>0 1 0 0 0 0 0 1 0 1 1 1 1 1 1
>1 1 1 1 0 0 1 0 1 1 0 1 0 0 1
>1 0 1 0 0 1 0 0 0 0 1 0 1 0 0
>1 0 1 0 1 1 1 0 0 0 0 0 1 0 0
>
>test2
>1 1 1 1 1 1 0 1 1 1 1 1 0 1 0
>1 1 1 0 0 1 0 0 0 1 0 0 1 1 1
>1 1 1 0 0 1 0 1 0 0 0 1 1 1 1
>0 0 0 0 1 1 0 0 0 1 1 0 0 1 1
>1 1 1 1 0 1 0 1 0 1 0 0 0 1 1
>0 1 0 0 0 1 0 0 0 1 1 0 1 0 0
>1 1 0 1 0 1 1 1 0 0 1 0 1 0 0
>1 1 0 1 0 1 1 1 0 1 0 1 1 0 0
>0 1 1 1 1 1 1 0 1 1 0 1 1 0 0
>1 1 0 0 0 1 0 0 1 0 1 1 1 0 0
--
Jonathan Baron, Professor of Psychology, University of Pennsylvania
Home page: http://www.sas.upenn.edu/~baron
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list