[R] selecting columns based on values of two variables
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Sun Sep 6 16:59:31 CEST 2009
probably you're looking for
subset(capdist, ida %in% c("DEN","SWD","FIN") & idb %in%
c("DEN","SWD","FIN"))
I hope it helps.
Best,
Dimitris
Thomas Jensen wrote:
> Dear R-list,
>
> I am having troubles selecting rows from a very large data-set
> containing distances between capitals.
>
> The structure of the data-set looks like this:
>
> numa ida numb idb kmdist midist
> 1 2 USA 20 CAN 731 456
> 2 2 USA 31 BHM 1623 1012
> 3 2 USA 40 CUB 1813 1130
>
>
> I want to select a subset of these dyads, and have tried the following
> code:
>
> subset(capdist,ida == c("DEN","SWD","FIN") & idb ==
> c("DEN","SWD","FIN"))
>
> This should ideally give me the dyads involving only Denmark, Sweden
> and Finland, however i get the error message:
>
> [1] numa ida numb idb kmdist midist
> <0 rows> (or 0-length row.names)
> Warning messages:
> 1: In is.na(e1) | is.na(e2) :
> longer object length is not a multiple of shorter object length
> 2: In `==.default`(ida, c("DEN", "SWD", "FIN")) :
> longer object length is not a multiple of shorter object length
> 3: In is.na(e1) | is.na(e2) :
> longer object length is not a multiple of shorter object length
> 4: In `==.default`(idb, c("DEN", "SWD", "FIN")) :
> longer object length is not a multiple of shorter object length
>
> Any help would be greatly appreciated,
>
> Best, Thomas Jensen
> [[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.
>
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
More information about the R-help
mailing list