Description Usage Arguments Details Value See Also Examples
Select rows based on minimum a valuein a given column
1 | KH.selectByMin(DT, groupBy, selectByMinOf)
|
DT |
data.table. Data object wich has at least one string / factor column and one numeric colum. |
groupBy |
character or vector of characters. Name of column to use for grouping rows of data.
If this is set to |
selectByMinOf |
character. Name of column to calculate |
This function groups rows of input data according to groupBy
value and filter the
codeMIN(selectByMinOf) for each group.
data.table. data.table oject with the same columns as input data set and rows containing the minimum of target column.
Other Datasets: KH.selectByMax
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | {
input_file <- system.file("extdata", "input_file.csv", package = "KHanSUtils")
DT <- KH.loadCSV(input_file)
DT
# year month day dep_delay arr_delay carrier origin dest air_time distance hour
# 1: 2014 10 31 -4 15 MQ LGA DTW 75 502 11
# 2: 2014 10 31 -8 16 MQ LGA RDU 83 431 11
# 3: 2014 10 31 -5 1 MQ LGA SDF 110 659 8
# 4: 2014 1 1 -8 -26 AA LGA PBI 157 1035 7
# 5: 2014 10 31 -5 -14 UA EWR IAH 189 1400 8
# 6: 2014 10 31 1 -30 UA LGA IAH 201 1416 14
# 7: 2014 1 1 4 0 AA EWR LAX 339 2454 18
# 8: 2014 1 1 2 1 AA JFK LAX 350 2475 13
# 9: 2014 1 1 2 9 AA JFK LAX 351 2475 19
#10: 2014 1 1 14 13 AA JFK LAX 359 2475 9
#11: 2014 1 1 -3 13 AA JFK LAX 363 2475 11
groupBy <- c('carrier','origin')
selectByExtOf <- 'air_time'
KH.selectByMin(DT,groupBy, selectByExtOf)
# carrier origin year month day dep_delay arr_delay dest air_time distance hour
# 1: AA EWR 2014 1 1 4 0 LAX 339 2454 18
# 2: AA JFK 2014 1 1 2 1 LAX 350 2475 13
# 3: AA LGA 2014 1 1 -8 -26 PBI 157 1035 7
# 4: MQ LGA 2014 10 31 -4 15 DTW 75 502 11
# 5: UA EWR 2014 10 31 -5 -14 IAH 189 1400 8
# 6: UA LGA 2014 10 31 1 -30 IAH 201 1416 14
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.