Skip to content

combining column having same values

4 messages · Eliza Botto, ONKELINX, Thierry, arun +1 more

#
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
Kliniekstraat 25
1070 Anderlecht
Belgium
+ 32 2 525 02 51
+ 32 54 43 61 85
Thierry.Onkelinx at inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

The combination of some data and an aching desire for an answer does not ensure that a reasonable answer can be extracted from a given body of data.
~ John Tukey

-----Oorspronkelijk bericht-----
Van: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Namens eliza botto
Verzonden: woensdag 6 maart 2013 12:26
Aan: r-help at r-project.org
Onderwerp: [R] combining column having same values


Dear useRs,
I have a matrix in the following form

 [,1]   [,2]   [,3]   [,4]   [,5]   [,6]   [,7]   [,8]   [,9]  [,10]  [,11]      1      1       3      2       3       1      1       2      3       3      2

and following is my desired output  (combining the column headers, having same values).
a<-1,2,6,7

b<-3,5,9,10

c<-4,8,11
Thanks in advance
Elisa

______________________________________________
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.
* * * * * * * * * * * * * D I S C L A I M E R * * * * * * * * * * * * *
Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is door een geldig ondertekend document.
The views expressed in this message and any annex are purely those of the writer and may not be regarded as stating an official position of INBO, as long as the message is not confirmed by a duly signed document.
#
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.




----- Original Message -----
From: eliza botto <eliza_botto at hotmail.com>
To: "r-help at r-project.org" <r-help at r-project.org>
Cc: 
Sent: Wednesday, March 6, 2013 6:26 AM
Subject: [R] combining column having same values


Dear useRs,
I have a matrix in the following form

[,1]?  [,2]?  [,3]?  [,4]?  [,5]?  [,6]?  [,7]?  [,8]?  [,9]? [,10]? [,11]? ? ? 1? ? ? 1? ? ?  3? ? ? 2? ? ?  3? ? ?  1? ? ? 1? ? ?  2? ? ? 3? ? ?  3? ? ? 2

and following is my desired output? (combining the column headers, having same values).
a<-1,2,6,7

b<-3,5,9,10

c<-4,8,11
Thanks in advance
Elisa ??? ???  ??? ?  ??? ??? ? 
??? [[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.
#
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: