2 ms·
The tasks were different. AWK -> calculate the difference between every two lines: awk -F ',' 'NR!=1{printf "%.0f\n", $1-ll}NR==1{print ""}{ll=$1}' R -> Ca
by arendtio 7y ago
The tasks were different.
AWK -> calculate the difference between every two lines:
awk -F ',' 'NR!=1{printf "%.0f\n", $1-ll}NR==1{print ""}{ll=$1}'
R -> Calculate the min, median, mean, and max:
d<-scan("stdin", quiet=TRUE)
cat(min(d), max(d), median(d), mean(d), sep=" ")
AFAIK, calculating the difference to its previous line for every line should be faster for data that is not sorted. I didn't try to write that one in R though.
I am sure there ways to make both things faster, I was just surprised as I didn't expect R to be faster with those two naive implementations.