Rscript -e 'df <- read.csv("data.csv"); print(head(df, 3))'

Category: Data Science & Analysis

Rscript -e 'df <- read.csv("data.csv"); print(head(df, 3))'

Show the first 3 rows of a data frame

head() prints the first n rows of a data frame, here 3, with column names as the header. It is the R version of head for tabular data and the standard first step after loading a file. Use tail() for the last rows or str(df) for a compact structure dump. The print() wrapper makes the result visible in Rscript's non-interactive mode.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.