0

I am trying to calculate the percentiles of my dataframe rows.

My data looks similar to that:

YM      V
201401  1
201401  2
201402  3
201402  5

I now want to create a new data.frame, which looks like that:

YM     v1 v2 v3 v4 v5 v6 v7 v8 v9 v10
201401
201402

In this data frame there should be e.g. in the columns v1 the first percentile of my variable for the month January 2014.

I tried to use the apply function but it did not work:

apply(df1, 1:2 ,quantile , probs=seq(0,1, 0.1),na.rm=TRUE)

EDIT:

The aggregate function aggregate(V ~ YM, df, FUN = quantile , probs=seq(0,1, 0.1),na.rm=TRUE) of Sotos gives out my desired output, however if i want to apply it to a new data.frame, it gives out the original output:

df2 <- aggregate(V ~ YM, df, FUN = quantile , probs=seq(0,1, 0.1),na.rm=TRUE)

Why is that?

Max
  • 49
  • 6

0 Answers0