How to create an empty data frame with fixed number of rows and without columns in R?


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.frame function as shown in the below examples.

Example1

Live Demo

> df1<-data.frame(matrix(,nrow=10,ncol=0))
> df1

Output

data frame with 0 columns and 10 rows

Example2

Live Demo

> df2<-data.frame(matrix(,nrow=100,ncol=0))
> df2

Output

data frame with 0 columns and 100 rows

Example3

Live Demo

> df3<-data.frame(matrix(,nrow=39,ncol=0))
> df3

Output

data frame with 0 columns and 39 rows

Example4

Live Demo

> df4<-data.frame(matrix(,nrow=20,ncol=0))
> df4

Output

data frame with 0 columns and 20 rows

Example5

Live Demo

> df5<-data.frame(matrix(,nrow=200,ncol=0))
> df5

Output

data frame with 0 columns and 200 rows

Example6

Live Demo

> df6<-data.frame(matrix(,nrow=150,ncol=0))
> df6

Output

data frame with 0 columns and 150 rows

Example7

Live Demo

> df7<-data.frame(matrix(,nrow=1000,ncol=0))
> df7

Output

data frame with 0 columns and 1000 rows

Example8

Live Demo

> df8<-data.frame(matrix(,nrow=500,ncol=0))
> df8

Output

data frame with 0 columns and 500 rows

Example9

Live Demo

> df9<-data.frame(matrix(,nrow=50000,ncol=0))
> df9

Output

data frame with 0 columns and 50000 rows

Example10

> df10<-data.frame(matrix(,nrow=10000000,ncol=0))
> df10

Output

data frame with 0 columns and 10000000 rows

Updated on: 05-Jan-2021

1K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements