Skip to content

connecting matrices

3 messages · arun, Eliza Botto

#
Dear Elisa,
Try this:
el<- matrix(1:100,ncol=20)
?set.seed(25)
?el1<- matrix(sample(1:100,20,replace=TRUE),ncol=1)

In the example you showed, there were no column names.? 

?list(el[,sort(el1)[1:3]],sort(el1,index.return=TRUE)$ix[1:3])
#[[1]]
?# ?? [,1] [,2] [,3]
#[1,]?? 31?? 61?? 71
#[2,]?? 32?? 62?? 72
#[3,]?? 33?? 63?? 73
#[4,]?? 34?? 64?? 74
#[5,]?? 35?? 65?? 75
#
#[[2]]
#[1] 9 5 3
A.K.
#
HI Elisa,
I guess there is a mistake.
Check whether this is what you wanted.

indx<-sort(el1,index.return=TRUE)$ix[1:3]
list(el[,indx],indx)
#[[1]]
?# ?? [,1] [,2] [,3]
#[1,]?? 41?? 21?? 11
#[2,]?? 42?? 22?? 12
#[3,]?? 43?? 23?? 13
#[4,]?? 44?? 24?? 14
#[5,]?? 45?? 25?? 15
#
#[[2]]
#[1] 9 5 3
A.K.



----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: eliza botto <eliza_botto at hotmail.com>
Cc: R help <r-help at r-project.org>
Sent: Thursday, April 25, 2013 10:09 AM
Subject: Re: connecting matrices

Dear Elisa,
Try this:
el<- matrix(1:100,ncol=20)
?set.seed(25)
?el1<- matrix(sample(1:100,20,replace=TRUE),ncol=1)

In the example you showed, there were no column names.? 

?list(el[,sort(el1)[1:3]],sort(el1,index.return=TRUE)$ix[1:3])
#[[1]]
?# ?? [,1] [,2] [,3]
#[1,]?? 31?? 61?? 71
#[2,]?? 32?? 62?? 72
#[3,]?? 33?? 63?? 73
#[4,]?? 34?? 64?? 74
#[5,]?? 35?? 65?? 75
#
#[[2]]
#[1] 9 5 3
A.K.