Building a table with values that break up a continuous variable in two groups

后端 未结 4 753
眼角桃花
眼角桃花 2021-01-19 10:31

I am looking for your help. I am trying to divide a continuous variable in two groups, I put this example about what I am trying to do:

x=data.frame(v1=c(1,1         


        
4条回答
  •  青春惊慌失措
    2021-01-19 11:10

    You can simply use summary here with lapply

    do.call(rbind,lapply( v,function(x) {
      v1.inf <- summary(v1[v1<=x])
      v1.sup <- summary(v1[v1>x])
      m <- as.matrix(rbind(v1.inf,v1.sup))
      rownames(m) <- paste(x,c('inf','sup'),sep='')
      m
    }))
    
           Min. 1st Qu. Median   Mean 3rd Qu. Max.
    10inf     1    2.75    5.0  5.344    8.00    9
    10sup    11   17.50   42.5 48.500   75.25  100
    20inf     1    4.00    6.0  6.216    9.00   15
    20sup    25   40.00   67.0 62.620   89.00  100
    30inf     1    4.00    6.0  7.308    9.00   30
    30sup    34   48.00   67.0 69.000   89.50  100
    50inf     1    4.25    7.0  9.619    9.00   45
    50sup    51   67.00   83.5 80.000   92.00  100
    70inf     1    5.00    8.0 13.090   11.00   67
    70sup    78   89.00   90.0 91.000   98.00  100
    90inf     1    5.00    8.0 17.620   12.00   90
    90sup    98   98.50   99.0 99.000   99.50  100
    110inf    1    5.00    8.5 20.880   22.50  100
    110sup   NA      NA     NA    NaN      NA   NA
    130inf    1    5.00    8.5 20.880   22.50  100
    130sup   NA      NA     NA    NaN      NA   NA
    150inf    1    5.00    8.5 20.880   22.50  100
    150sup   NA      NA     NA    NaN      NA   NA
    170inf    1    5.00    8.5 20.880   22.50  100
    170sup   NA      NA     NA    NaN      NA   NA
    190inf    1    5.00    8.5 20.880   22.50  100
    190sup   NA      NA     NA    NaN      NA   NA
    

提交回复
热议问题