Add a Column to Data Frame in R


There are three common ways to add a new column to a data frame in R: the $ operator, brackets and Cbind. As a comparison, here is the SQL syntax to add a column to a table: ALTER TABLE table_name ADD column_name datatype;

The first way is to use the $ operator.

For more information check out the article called How to Add a Column to a Data Frame in R (With Examples) over at Statology.

You have a data frame called df. There is a column in that data frame that has the date and time and you widsh to extract the date and put it in a new column called date.

df$date <- as.Date(df$started)

Leave a Reply