Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
in Data Science by (50.2k points)

I need to create an empty data frame in R with specified column names. Any simplest way?

1 Answer

0 votes
by (108k points)

 You just have to create a data

.frame with 0 length variables

for example:

nodata <- data.frame(x= numeric(0), y= integer(0), z = character(0))


## 'data.frame':    0 obs. of 3 variables:

##  $ x: num 

##  $ y: int 

##  $ z: Factor w/ 0 levels: 

or to create a data.frame with 5 columns named a,b,c,d,e

nodata <-,numeric(0), simplify = F), letters[1:5]))

If you wish to learn more about R Programming visit this R Programming Course.


Browse Categories