[R] Shape manipulation

Greg Snow 538280 at gmail.com
Sat Mar 3 21:18:08 CET 2012


A general solution if you always want 2 columns and the pattern is
always every other column (but the number of total columns could
change) would be:

cbind(  c(Dat[,c(TRUE,FALSE)]), c(Dat[,c(FALSE,TRUE)]) )



On Sat, Mar 3, 2012 at 11:40 AM, David Winsemius <dwinsemius at comcast.net> wrote:
>
> On Mar 3, 2012, at 11:02 AM, Bogaso Christofer wrote:
>
>> Hi all, let say I have following matrix:
>>
>>
>>
>>> Dat <- matrix(1:30, 5, 6); colnames(Dat) <- rep(c("Name1", "Names2"), 3)
>>
>>
>>> Dat
>>
>>
>>    Name1 Names2 Name1 Names2 Name1 Names2
>>
>> [1,]     1      6    11     16    21     26
>>
>> [2,]     2      7    12     17    22     27
>>
>> [3,]     3      8    13     18    23     28
>>
>> [4,]     4      9    14     19    24     29
>>
>> [5,]     5     10    15     20    25     30
>>
>>
>>
>>> From this matrix, I want to create another matrix with 2 columns for
>>> "Name1"
>>
>> and "Name2". Therefore, my final matrix will have 2 columns and 15 rows.
>> Is
>> there any direct R function to achieve this?
>>
>
> rbind(Dat[,1:2], Dat[,3:4], Dat[,5:6])
>
>>        [[alternative HTML version deleted]]
>
>
> Bogaso;
>
> It is really long past due for you to learn how to send plain text messages
> from your mailer.
>
> --
>
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> 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.



-- 
Gregory (Greg) L. Snow Ph.D.
538280 at gmail.com



More information about the R-help mailing list