Rscript -e 'x <- c(1,2,3); print(mean(x))'

Category: Data Science & Analysis

Rscript -e 'x <- c(1,2,3); print(mean(x))'

Compute the mean of a vector in R

The c() function builds a vector from its arguments, the <- operator assigns it to x, and mean() computes the average. Semicolons separate statements within the -e string. This is the minimal R one-liner pattern for any computation. Replace mean with median, sd, or var for other statistics.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.