subset data frame based on percentage

送分小仙女□ 提交于 2019-11-29 10:31:52

问题


i have a data frame that contains a data like this :

V1 V2 V3
1  2  0.34
1  3  0.31
1  4  0.12
1  5  0.12

the data frame is bigger but that's an example.

i want to take a subset of this data frame that has the lowest 20% of V3.

how this can be done ?

thanks for help


回答1:


The subset() function is handy because (among other benefits) it allows you to avoid having to repeatedly mention the name of the data-frame:

subset(dataFrame, V3 <= quantile(V3, 0.2))



回答2:


ss <- subset(dataFrame, subset=(dataFrame$V3 <= quantile(dataFrame$V3, 0.20)))


来源:https://stackoverflow.com/questions/6253837/subset-data-frame-based-on-percentage

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!