VOOZH about

URL: https://www.geeksforgeeks.org/r-language/create-empty-dataframe-with-only-column-names-in-r/

⇱ Create empty DataFrame with only column names in R - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Create empty DataFrame with only column names in R

Last Updated : 23 Jul, 2025

In this article, we are going to discuss how to create a data frame in r with column names and create an empty data frame with column names in the R Programming Language.

The basic syntax for creating a data frame is using data. frame().

Create a Data Frame with Values and column Names

Output:

 ID Names Address Phone Aadhaar.No
1 1 Vipul 123 Main St 555-1111 123-456-789
2 2 Jayesh 456 Oak St 555-2222 456-789-123
3 3 Shivang 789 Pine St 555-3333 789-123-456

Create Data Frame with Column Names from Matrix

Output:

 ID Names Scores
1 1 5 9
2 2 6 10
3 3 7 11
4 4 8 12

Create empty DataFrame with only column names in R

Syntax: data.frame(input_data,nrow,ncol)

Parameter:

  • input_data may be values of list or vector.
  • nrow specifies the number of rows
  • ncol specifies the number of columns.

Steps -

  • Create an empty dataframe
  • Define the column names to a variable
  • Assign that variable to the dataframe.
  • Display data frame so created

We can assign column names to dataframe by using colnames()

Syntax:

colnames(dataframe_name)

Given below is the implementation using the above approach.

Output:

[1] id names address phone aadhaar no
<0 rows> (or 0-length row.names)

If we specify nrow parameter with morethan 0, it will take NA as that many rows.

Output:

 id names address phone aadhaar no
1 NA NA NA NA NA
2 NA NA NA NA NA
3 NA NA NA NA NA
4 NA NA NA NA NA
5 NA NA NA NA NA
6 NA NA NA NA NA
Comment

Explore