Irene232545
Irene232545

Reputation: 31

Find quantile for whole dataframe

I want to find the quantile of my whole df.

a <- rbind(5, 10, 1.5)
b <- rbind(1.5, 6.7, 7)
c <- rbind(3.5, 10.2, 5)
df <- data.frame(a,b,c)
> quantile(df)
Error in `[.data.frame`(x, order(x, na.last = na.last, decreasing = decreasing)) : 
  undefined columns selected

Can somebody help me?

Upvotes: 1

Views: 63

Answers (1)

akrun
akrun

Reputation: 887831

We can unlist and convert to vector as according to ?quantile documentation the input x is

x - numeric vector whose sample quantiles are wanted, or an object of a class for which a method has been defined (see also ‘details’). NA and NaN values are not allowed in numeric vectors unless na.rm is TRUE.

Thus, unlist to create a vector and get the quantile for the whole data

quantile(unlist(df))
#  0%  25%  50%  75% 100% 
# 1.5  3.5  5.0  7.0 10.2 

Upvotes: 1

Related Questions