[R] How to select a subset <number of dimensions matter>
Steve Lianoglou
mailinglist.honeypot at gmail.com
Fri Oct 2 16:56:03 CEST 2009
Hi,
On Oct 2, 2009, at 10:47 AM, Hyo Lee wrote:
> Hi guys,
> I need your help.
>
> I would like to select a subset from a dataset.
> This is the dimension of the dataset.
>
>> dim(data1)
> [1] 72 36 1916
>
> so, it's like.. there are 1916 of 72 * 36 matrix. ==> looks like 72
> * (
> 36*1916 )
> **
> *1)*
> And I would like to select the first 72*36 matrix. This is how I did:
>
>> two=data1[,1:36]
> Error in data1[, 1:36] : incorrect number of dimensions
You have an object with three dimensions, but only passing in two dims
to "slice" with.
>
> Do you have any idea how I should fix this?
This is a similar array : think of it as 5 10x2 matrices
R> m <- array(1:100, dim=c(10,2,5))
I can get the first 10x2 matrix like so:
R> m[,,1]
[,1] [,2]
[1,] 1 11
[2,] 2 12
[3,] 3 13
[4,] 4 14
[5,] 5 15
[6,] 6 16
[7,] 7 17
[8,] 8 18
[9,] 9 19
[10,] 10 20
The second would be: m[,,2]
Does answering the first question take care of the rest?
-steve
>
> *2) *I thought about another way to deal with this problem.
> Firstly, I name the each column variable:
>
>> colnames(data1)=paste('lati',1:36)
>
> and then select:
>
>> one=subset(data1,subset=TRUE, select = lati1:lati36)
>
> but the problem is that, although I tried to select only 36 columns,
> above
> command selects the all columns. (36*1916 =68976)
> I think if I can name all the variables at one time, say ,
> colnames(data1)=paste('lati',1:68976) ,then it wouldn't have been a
> problem.
> (but obviously, <---this command does not work)
> Do you have any idea how to deal with this??
>
>
> *3)* After all, what I would really like to do is to transpose the
> data:
> The dataset I have above is 72*68976. (hard to export to csv; since
> max
> column# is 18000 something.)
> I have to transpose the data.. obviously.
> But, the problem is, after I transpose the data and export it to
> csv, I
> can't really see the data.
> Besides, I think tranpose thing does not seem work as I want,
>> bbb=t(as.matrix(data1))
>> write.csv(bbb,"c:/oo.csv")
>
> Please help me,
> Thanks.
>
> -Hyo
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact
More information about the R-help
mailing list