Create a table with values from ecdf graph

后端 未结 2 1272
-上瘾入骨i
-上瘾入骨i 2021-01-26 09:06

I am trying to create a table using values from an ecdf plot. I\'ve recreated an example below.

#Data
data(mtcars)

#Sort by mpg
mtcars <- mtcars[order(mtcars$mpg),]         


        
2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-26 09:57

    A much shorter answer that I can't believe I didn't see earlier. Essentially I just divide the number of rows equal to or less than .25, .5, and .75 by the total number of rows, for each cyl.

    cyl.table<-mtcars %>%
      group_by(cyl) %>%
        summarise("25% Picked" = sum(Percent_Picked<=0.25)/(sum(Percent_Picked<=1)),
                  "50% Picked" = sum(Percent_Picked<=0.5)/(sum(Percent_Picked<=1)),
                  "75% Picked" = sum(Percent_Picked<=0.75)/(sum(Percent_Picked<=1)))
    cyl.table
    

提交回复
热议问题