0

I have one data frame and with 2 columns and 3 rows, and I want to get the min and max value of the second column, I can get that with min(data[,2]), but my problem is, I have to increment the second column when the number requested is matched to the first column. Here comes the interesting part when i increment 2 different rows the max and min only compare to those two instead of all column. The initial data frame is:

   item   freq   
1:    4      1
2:    3      1
3:    1      1

The request are 3,3,4. And the data frame become like this:

   item   freq
1:    4      2
2:    3      3
3:    2      1

And I want to know the max and min and I get max=3 and min=2 and the min should be 1.

André
  • 23
  • 4
  • Either way the solution to your question is `min(data[, freq]); max(data[, freq])` or `min(data[, 2, with = FALSE]); max(data[, 2, with = FALSE])` or just `data[, range(freq)]`. Please the vignettes [here](https://github.com/Rdatatable/data.table/wiki/Getting-started) and try being aware when you are using a `data.frame` or a `data.table` – David Arenburg Jul 28 '15 at 10:12
  • Thanks David with max(data[,2,with=FALSE]) and the same for min it worked. – André Jul 28 '15 at 10:38
  • 1
    It's better to use real column names instead of indexes and you can just use `range` to get both `data[, range(freq)]` – David Arenburg Jul 28 '15 at 10:41

0 Answers0