Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

subset data frame based on percentage

Tags:

r

subset

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

like image 893
smack Avatar asked Jun 06 '11 14:06

smack


People also ask

How do I subset a Dataframe based on column value in R?

How to subset the data frame (DataFrame) by column value and name in R? By using R base df[] notation, or subset() you can easily subset the R Data Frame (data. frame) by column value or by column name.

How do you use subset of data?

Subset a Data Frame with Base R Extract[]To specify a logical expression for the rows parameter, use the standard R operators. If subsetting is done by only rows or only columns, then leave the other value blank. For example, to subset the d data frame only by rows, the general form reduces to d[rows,] .


2 Answers

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))
like image 59
Prasad Chalasani Avatar answered Oct 03 '22 02:10

Prasad Chalasani


ss <- subset(dataFrame, subset=(dataFrame$V3 <= quantile(dataFrame$V3, 0.20)))
like image 42
Jubbles Avatar answered Oct 03 '22 03:10

Jubbles