[R] Combinations and table selection problem (reviewed)

Carlos Guerra carlosguerra at esa.ipvc.pt
Mon Mar 8 18:37:26 CET 2010


Dear all,

I have the following dataset:

t <- structure(list(pUrb = c(20.160307, 51.965649, 26.009581, 3.141484, 64.296826
    ), pUrb_class = structure(c(1L, 1L, 1L, 1L, 1L), .Label = c("0", 
    "1"), class = "factor"), pAgri = c(79.921386, 46.657713, 
    40.269204, 0, 0.440691), pAgri_class = structure(c(1L, 1L, 
    1L, 1L, 1L), .Label = c("0", "1"), class = "factor"), pNatFor = c(0, 
    0, 0, 0, 0), pNatFor_class = structure(c(1L, 1L, 1L, 1L, 
    1L), .Label = c("0", "1"), class = "factor"), pArtFor = c(0, 
    0, 0, 0, 24.566125), pArtFor_class = structure(c(1L, 1L, 
    1L, 1L, 1L), .Label = c("0", "1"), class = "factor"), pMixFor = c(0, 
    0, 33.578923, 96.940185, 10.655666), pMixFor_class = structure(c(1L, 
    1L, 1L, 2L, 1L), .Label = c("0", "1"), class = "factor"), 
    pPioMo = c(0, 0, 0, 0, 0), pPioMo_class = structure(c(1L, 
    1L, 1L, 1L, 1L), .Label = c("0", "1"), class = "factor"), 
    SwiLU = c(0.565419, 0.937982, 1.071812, 0.056002, 0.831812
    ), SwiLU_class = structure(c(1L, 2L, 2L, 1L, 2L), .Label = c("1", 
    "0", "2"), class = "factor"), NumP = c(4L, 7L, 3L, 4L, 6L
    ), NumP_class = structure(c(2L, 3L, 1L, 2L, 3L), .Label = c("1", 
    "0", "2"), class = "factor"), Roaddist = c(1615.55, 2140.09, 
    2308.68, 2088.06, 2000), Roaddist_class = c(NA, NA, NA, NA, 
    NA), Roaddens = c(0, 0, 0, 0, 0), Roaddens_class = c(NA, 
    NA, NA, NA, NA), SwiSlo = c(0, 0, 0, 0, 0), SwiSlo_class = structure(c(1L, 
    1L, 1L, 1L, 1L), .Label = c("1", "2", "0", "3"), class = "factor"), 
    SwiAlt = c(0, 0, 0, 0, 0), SwiAlt_class = structure(c(1L, 
    1L, 1L, 1L, 1L), .Label = c("1", "2", "0", "3"), class = "factor")), .Names = c( 
"pUrb", "pUrb_class", "pAgri", "pAgri_class", "pNatFor", "pNatFor_class", 
"pArtFor", "pArtFor_class", "pMixFor", "pMixFor_class", "pPioMo", 
"pPioMo_class", "SwiLU", "SwiLU_class", "NumP", "NumP_class", 
"Roaddist", "Roaddist_class", "Roaddens", "Roaddens_class", "SwiSlo", 
"SwiSlo_class", "SwiAlt", "SwiAlt_class"), row.names = c("NF1885", "NF1886", 
"NF1893", "NF1894", "NF1895"), class = "data.frame")


#obtaining the number of combinations present in the data base#

library(survival)

w <- strata(t$NumP_class,t$SwiLU_class,t$pMixFor_class, sep=",")
table(w)
w
t$NumP_class=1,t$SwiLU_class=0,t$pMixFor_class=0 
                                               1 
t$NumP_class=0,t$SwiLU_class=1,t$pMixFor_class=0 
                                               1 
t$NumP_class=0,t$SwiLU_class=1,t$pMixFor_class=1 
                                               1 
t$NumP_class=2,t$SwiLU_class=0,t$pMixFor_class=0 
                                               2

#obtaining median value#

median(table(w))
[1] 1


In this stage I have 3 questions:

1st:
how can I obtain the combinations witch are present over the median (in this case the fourth combination)?

2nd:
how can I obtain the combinations witch are present over the median and have at least one condition > 2 (in this case the fourth combination)?

3rd:
how can I select/extract from the original table the rows witch comply with the 2nd question, in this case (row id: NF1895):


            pUrb pUrb_class     pAgri pAgri_class pNatFor pNatFor_class  pArtFor pArtFor_class  pMixFor
NF1895 64.296826          0  0.440691           0       0             0 24.56612             0 10.65567
       pMixFor_class pPioMo pPioMo_class    SwiLU SwiLU_class NumP NumP_class Roaddist Roaddist_class Roaddens
NF1895             0      0            0 0.831812           0    6          2  2000.00             NA        0
       Roaddens_class SwiSlo SwiSlo_class SwiAlt SwiAlt_class
NF1895             NA      0            1      0            1




Best Regards,

Carlos


More information about the R-help mailing list