Count characters in string
nchar("pomegranate")
## [1] 11
Count elements in a list
fruits <- c("mango", "pomegranate", "berries", "orange")
length(fruits) # number of elements in list
## [1] 4
nchar(fruits) # count of characters in string
## [1] 5 11 7 6
Count observations in data frame, iris
nrow(iris)
## [1] 150
Count number of variables in iris
ncol(iris)
## [1] 5
length(names(iris))
## [1] 5