![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
> df1<-data.frame(matrix(,nrow=10,ncol=0)) > df1
Output
data frame with 0 columns and 10 rows
Example2
> df2<-data.frame(matrix(,nrow=100,ncol=0)) > df2
Output
data frame with 0 columns and 100 rows
Example3
> df3<-data.frame(matrix(,nrow=39,ncol=0)) > df3
Output
data frame with 0 columns and 39 rows
Example4
> df4<-data.frame(matrix(,nrow=20,ncol=0)) > df4
Output
data frame with 0 columns and 20 rows
Example5
> df5<-data.frame(matrix(,nrow=200,ncol=0)) > df5
Output
data frame with 0 columns and 200 rows
Example6
> df6<-data.frame(matrix(,nrow=150,ncol=0)) > df6
Output
data frame with 0 columns and 150 rows
Example7
> df7<-data.frame(matrix(,nrow=1000,ncol=0)) > df7
Output
data frame with 0 columns and 1000 rows
Example8
> df8<-data.frame(matrix(,nrow=500,ncol=0)) > df8
Output
data frame with 0 columns and 500 rows
Example9
> 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
Advertisements