R Program to create an empty data frame

How to create an empty data frame

Here we are explaining how to write an R program to create an empty data frame. Here we are using a built-in function data.frame() for creating it. A data frame is used for storing data tables which has a list of vectors with equal length. The data frames are created by function data.frame(), which has tightly coupled collections of variables.

 

How to create an empty data frame in R Program

Below are the steps used in the R program to create an empty data frame. In this R program, we directly give the values to the built-in function. And print the function result. Here we used the variable Df is used as a data frame. The data frame consists of different data types which are integer, Doubles, Characters, Logical, Factors, StringsAs Factors.

ALGORITHM

STEP 1: Consider variable Df as a data frame.

STEP 2: Call data.frame() with different data types

STEP 3: Assign Df with function result

STEP 4: print the result of the function

 

R Source Code

                                          Df = data.frame(Ints=integer(),
                Doubles=double(),
                Characters=character(),
                Logicals=logical(),
                Factors=factor(),
                stringsAsFactors=FALSE)
print("Structure of the empty dataframe:")
print(str(Df))

                                      

OUTPUT

[1] "Structure of the empty dataframe:"
'data.frame': 0 obs. of  5 variables:
 $ Ints      : int 
 $ Doubles   : num 
 $ Characters: chr 
 $ Logicals  : logi 
 $ Factors   : Factor w/ 0 levels: 
NULL