Add One Empty Column to dataframe
Here we are going to add an empty column to the dataframe by assigning column values as NA.
Syntax:
dataframe[ , 'column_name'] = NA
where,
- dataframe is the input dataframe
- column_name is the new column name
Example: R program to create a dataframe with 3 columns and add an empty column
R
# create a dataframe with 4 rows and 3 columns data = data.frame (marks1= c ( '90' , '78' , '89' , '76' ), marks2= c ( '92' , '68' , '78' , '96' ), marks3= c ( '90' , '78' , '89' , '76' )) # add an empty column named empty_column data[, 'empty_column' ] = NA # display print (data) |
Output:
How to Add an Empty Column to DataFrame in R?
In this article, we will discuss how to add an empty column to the dataframe in R Programming Language.
Contact Us