[R] data manipulation
Liaw, Andy
andy_liaw at merck.com
Sat Apr 23 23:37:23 CEST 2005
You just need to try harder in reading the documentation. Try:
data <- matrix(scan("file-name"), ncol=29, byrow=TRUE)
Andy
> From: Yoko Nakajima
>
> Hello,
>
> may I ask a further question?
>
> I have realized that "data <-
> matrix(scan("file-name"), ncol=29)" will read the data
> differently than I
> thought, i.e., (4,1) is the first column, (17,1) is the
> second column, and
> (1,1) is the third and so on by this code - please see the data below.
> Therefore, the data set I have would not be in order if I
> used this code.
>
> It needed to be read as: (4.4) first column, (1,1) the second
> column, and
> (17, 17) is the third and so on (i.e., from 4 to 0.5611 makes
> the first row
> and another 4 to 0.5611 makes the second row and so on). So,
>
> V1 V2 V3 ... V29
> 4 1 17 ... 0.5611
> 4 1 17 ... 0.5611
>
> was needed.
>
> (Now I have ,
> V1 V2 V3 .... V29
> 4 17 1 ... 0.6578
> 1 1 -5.1536 ... 0.5611)
>
>
> [The data set I have may have around 1000 sets of them (29
> variables times
> around 1000 sets of these 29 variables). I only paste here two sets of
> them.]
> 4 1 17 1 1
> -5.1536 -0.1668 -2.3412 -0.5062 0.9621 0.3640 0.3678
> -0.5081 -0.2227
> 0.8142 -0.0389 -0.0445 -0.0578 -0.1175 -0.1232 0.8673
> -0.1033 -0.0796
> -0.0341 -0.1716 -0.1801 -0.7014 0.6578 0.5611
>
> 4 1 17 2 1
> -5.1536 -0.1668 -2.3412 -0.5062 0.9621 0.3640 0.3678
> -0.5081 -0.2227
> 0.8142 -0.0389 -0.0445 -0.0578 -0.1175 -0.1232 0.8673
> -0.1033 -0.0796
> -0.0341 -0.1716 -0.1801 -0.7014 0.6578 0.5611
>
>
>
> I need 29 columns. This is true. But the data was read differently by
> "ncol=29". Is there any way I can handle this problem by R?
>
> I would very appreciate it if you could let me know. My guess
> is that I
> should probably rearrange the data set by excel etc.. I have used
> "data.entry(data)" and found this. I can not analyze this data set.
>
> Thank you very much, in advance.
> Sincerely,
> Yoko.
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
>
More information about the R-help
mailing list