[R] Merge vectors

Mark Knecht markknecht at gmail.com
Thu Jul 23 00:22:15 CEST 2009


Sort of like this?

> A<-c(3,5,7,18,43,85,91,98,100,130,230,487) #data values
> B<-c(10,5,5,10,8,11,2,7,3,11,10)  #random numbers (sample)
>
> C = A[B]
> C
 [1] 130  43  43 130  98 230   5  91   7 230 130

On Wed, Jul 22, 2009 at 2:08 PM, Erik Iverson<eiverson at nmdp.org> wrote:
> A[B]
>
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of MarcioRibeiro
> Sent: Wednesday, July 22, 2009 2:31 PM
> To: r-help at r-project.org
> Subject: [R] Merge vectors
>
>
> Hi listers,
> I would like to merge two vectors as follows...
> A<-c(3,5,7,18,43,85,91,98,100,130,230,487) #data values
> B<-c(10,5,5,10,8,11,2,7,3,11,10)  #random numbers (sample)
> I would like to set the vector of random numbers according to the order set
> of the vector of data values...
> The result would be: (130,43,43,130,98,230,5,91,7,230,130)
> I could do this with merging, but I would need to set a primary key to merge
> the vectors... Is there a way of doing directly...
> Thanks in advance,
> Marcio
>
>
> --
> View this message in context: http://www.nabble.com/Merge-vectors-tp24612997p24612997.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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.
>
> ______________________________________________
> 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.
>




More information about the R-help mailing list