8 ms·
The second example should be written like this: diamondsDT[cut != "Fair", .(AvgPrice = mean(price), MedianPrice = as.numeric(me
by educationdata 7y ago
The second example should be written like this:
diamondsDT[cut != "Fair", .(AvgPrice = mean(price),
MedianPrice = as.numeric(median(price)),
Count = .N), cut][order(-Count)]
There is no need to break it to 10 lines.
- cwyers 7y agoI honestly find that less readable than Hadley's version, especially turning "by = cut" into "cut." This is where terseness really cuts into readability (and positional arguments is one of my least favorite features about R in terms of long-term readability of code).