Here is how I can do that:
df <- data.frame(a=1:200)
df$a <- NULL
df
Result:
data frame with 0 columns and 200 rows
Can the same be achieved with only one command?
To create an empty data frame with fixed number of rows but no columns, we can use data. frame function along with the matrix function. That means we need to create a matrix without any column using matrix and save it in a data frame using data.
One simple approach to creating an empty DataFrame in the R programming language is by using data. frame() method without any params. This creates an R DataFrame without rows and columns (0 rows and 0 columns).
Create Empty Dataframe With Size You can create a dataframe with a specified size for both columns and rows. Use the range function to create a sequence of numbers and pass it to the index range or the columns range specify column and row sizes.
This can work (if the call to 2 functions is not considered 2 commands):
data.frame(matrix(, nrow=200, ncol=0))
#data frame with 0 columns and 200 rows
Edit: Another option is data.frame()[1:200, ]
:
data.frame()[1:200, ]
# data frame with 0 columns and 200 rows
What about this?
data.frame(row.names = 1:200)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With