Hello,
Try
x <- scan(text = " 1 1 3 2 3 1 1
2 3 3 2")
sapply(unique(x), function(.x) which(x == .x))
Hope this helps,
Rui Barradas
Em 06-03-2013 11:26, eliza botto escreveu:
Dear useRs,
I have a matrix in the following form
[,1] [,2]
Hi,
Try this:
mat1<- as.matrix(read.table(text="
1 1 3 2 3 1 1 2 3 3 2
",sep="",header=FALSE))
res<-lapply(1:3,function(i) which(mat1==i))
names(res)<- c("a","c","b")
res
#$a
#[1] 1 2 6 7
#$c
#[1] 4 8 11
#$b
#[1] 3 5 9 10
A.K.
- O
Dear Eliza,
You question is not very clear. I think you are looking for the which()
function.
Best regards,
Thierry
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature and
Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Klin
3 matches
Mail list logo