0

I have an question that seems simple but is stumping me. My time series data looks like:

Year Percentile Value
1990 p.10 20
1990 p.50 30
1990 p.90 40

I am trying to select the Value observations that correspond to the 10th percentile (e.g., p.10).

Terru_theTerror
  • 4,918
  • 2
  • 20
  • 39
James
  • 123
  • 1
  • 8
  • You mean something like [this](https://stackoverflow.com/questions/3445590/how-to-extract-a-subset-of-a-data-frame-based-on-a-condition-involving-a-field)? – pogibas Mar 02 '18 at 15:31
  • look at `dplyr::filter()` – Jan Kislinger Mar 02 '18 at 15:32
  • The first suggestion doesn't work because I'm not subsetting a dataframe, I'm subsetting a vector within dataframe, according to other vector's values in the dataframe... – James Mar 02 '18 at 15:38

2 Answers2

0

As Jan said, dplyr::filter is helpful for things like this. library(dplyr) percentiledata <- dplyr::filter(data, Percentile == "p.10")

Anonymous coward
  • 2,061
  • 1
  • 16
  • 29
  • The issue is that I don't want a subsetted dataframe as a result. I want a vector of the variable Value, that only contains Value observations for when the percentile is p.10. – James Mar 02 '18 at 15:43
  • @James We can use the `pull` function after the `filter` function (https://stackoverflow.com/questions/21618423/extract-a-dplyr-tbl-column-as-a-vector). – www Mar 02 '18 at 15:59
0
 subset(dat,grepl("10",Percentile))
  Year Percentile Value
1 1990       p.10    20
Onyambu
  • 67,392
  • 3
  • 24
  • 53