`dim()` is a base R function that returns an object's dimensions. For a data frame, the result lists the number of rows first and the number of columns second. It is a fast way to confirm that an import produced the expected data shape before analysis begins. section 2.2 section 6.2
Check a newly imported draft data set
After importing `draft.csv`, run `dim(draft)`. The output `293 26` means the data contains 293 records and 26 variables. That immediate check confirms that R received a data set of the expected size. section 2.2
dim(draft) ## [1] 293 26
The two returned values give row count followed by column count. section 2.2
Use `dim()` again after a wrangling step to verify what changed. Removing two poorly tracked variables from `hustle` leaves its 90 rows intact while reducing its width from 14 columns to 12. section 5.3 section 15.3
Dimension checks make common data operations easier to verify:
- After `filter()`, confirm that unwanted records were removed while the needed variables remain. section 15.3
- After `select()`, confirm that the number of columns fell as intended. section 6.3.2
- After `rbind()`, confirm that rows from matching data sets were stacked while the column count stayed the same. section 14.2.4
- After `cbind()` or `left_join()`, confirm that matched data sets have the expected row and column counts. section 7.3 section 6.3.2
- After splitting data for modeling, confirm the sizes of training and test sets. section 14.6.1
Compare two NBA seasons
Calling `dim(nba1819)` and `dim(nba1920)` shows that both data sets have 57 variables, but the 2019–20 data has fewer observations. The row difference reflects a shortened season, while the matching column counts show the files share the same structure. section 6.2
`dim()` reports shape only; it does not show variable names, types, or sample values. Pair it with `glimpse()` for a transposed, truncated view of a data set, or with `head()` and `tail()` when you also want to inspect records. section 3.3 section 14.2.4
