[R] Odp: Bind together two vectors of different length...
Petr PIKAL
petr.pikal at precheza.cz
Mon Jul 30 12:33:42 CEST 2007
Hi
r-help-bounces at stat.math.ethz.ch napsal dne 30.07.2007 12:09:59:
> Dear everyone,
>
> I've got difficulties in realizing the following
> task:
>
> I have two vectors:
> A <- c(1:10)
> B<- seq(1,10,2)
>
> Now I want to make a table form vectors A and B as rows, and if a value
of A
> isn't present B, then I want to put a N/A symbol in it:
>
> Output should look like this:
>
> 1 2 3 4 5 6 7 8 9 10
> 1 0 3 0 5 0 7 0 9 0
>
> How can I do this in R?
in your particular case
rbind(A,A*(A %in% B))
will give you such output, but 0 is not NA thereofore
> AO<-A*(A %in% B)
> AO[!(A %in% B)]<-NA
> rbind(A, AO)
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
A 1 2 3 4 5 6 7 8 9 10
AO 1 NA 3 NA 5 NA 7 NA 9 NA
gives you such output but with NA values instead of zeroes
Regards
Petr
>
> Thank you.
>
> --
> Andris Jankevics
> Assistant
> Department of Medicinal Chemistry
> Latvian Institute of Organic Synthesis
> Aizkraukles 21, LV-1006, Riga, Latvia
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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