w3resource

R Programming: Create an empty data frame

R Programming: Data frame Exercise-1 with Solution

Write a R program to create an empty data frame.

Sample Solution :

R Programming 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))

Sample 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                         

R Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: R Programming Data frame Exercises Home.
Next: Write a R program to create a data frame from four given vectors.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.




We are closing our Disqus commenting system for some maintenanace issues. You may write to us at reach[at]yahoo[dot]com or visit us at Facebook