R Set Dimensions of Empty Data Frame – n Rows & m Columns (Example Code)
In this R tutorial you’ll learn how to construct a data frame having n rows and m columns.
Example: Create Empty Data Frame with Certain Dimensions
my_df <- as.data.frame(matrix(0, nrow = 8, ncol = 5)) # Constructing empty data frame my_df # Showing empty data in RStudio console # V1 V2 V3 V4 V5 # 1 0 0 0 0 0 # 2 0 0 0 0 0 # 3 0 0 0 0 0 # 4 0 0 0 0 0 # 5 0 0 0 0 0 # 6 0 0 0 0 0 # 7 0 0 0 0 0 # 8 0 0 0 0 0 |
my_df <- as.data.frame(matrix(0, nrow = 8, ncol = 5)) # Constructing empty data frame my_df # Showing empty data in RStudio console # V1 V2 V3 V4 V5 # 1 0 0 0 0 0 # 2 0 0 0 0 0 # 3 0 0 0 0 0 # 4 0 0 0 0 0 # 5 0 0 0 0 0 # 6 0 0 0 0 0 # 7 0 0 0 0 0 # 8 0 0 0 0 0
Further Resources & Related Tutorials
Please find some additional R programming tutorials on topics such as data conversion, ggplot2, coding errors, and extracting data below: