Exploring dataset by various functions in R
Function Purpose
head(data) Shows the first 6 rows of the dataset
tail(data) Shows the last 6 rows of the dataset
dim(data) Returns the number of rows and columns
nrow(data) Number of rows
ncol(data) Number of columns
str(data) Shows structure: variable names, types, and a preview of values
summary(data) Provides summary statistics for each column
names(data) Lists the column names
colnames(data) Same as names(), but specifically for columns
rownames(data) Lists the row names (if any)
sapply(data, class) Shows the class/type of each column
table(data$var) Frequency count of unique values in a column
unique(data$var) Shows unique values in a column
anyNA(data) Checks if there are any missing values
[Link](data) Returns a logical matrix indicating NA positions
View(data) Opens the dataset in a spreadsheet-like viewer (RStudio only)
Example with iris dataset:
data(iris)
head(iris)
summary(iris)
str(iris)
table(iris$Species)