VOOZH about

URL: https://www.geeksforgeeks.org/r-language/how-to-add-column-to-dataframe-in-r/

⇱ How to add column to dataframe in R ? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to add column to dataframe in R ?

Last Updated : 26 Mar, 2021

In this article, we are going to see how to add columns to dataframe in R. First, let's create a sample dataframe.

Adding Column to the DataFrame

We can add a column to a data frame using $ symbol.

syntax: dataframe_name $ column_name = c( value 1,value 2 . . . , value n) 

Here c() function is a vector holds values .we can pass any type of data with similar type.  

Steps for adding a column to a dataframe.

  1. Create a data frame.
  2. Use the $ symbol as shown in the above syntax to add a column to a data frame.
  3. Print the updated data frame to see the changes.

Example 1: Creating a data frame.

👁 Image

Adding a column using $ symbol:

👁 Image

Example 2: Creating a data frame

👁 Image

Adding a column to the data frame

👁 Image
Comment

Explore