How to add a column to a data.frame in R?



I have a data frame of salaries in which I want to add the new column to existing data salaries and I want to name the column experience and I want to give column value of experience name exp.

'data.frame':	65 obs. of  2 variables:
 $ salary: num  58.8 34.8 163.7 70 55.5 ...
 $ degree: int  3 1 3 3 3 2 1 1 2 3 ...



you can create a new column in an existing data frame using


you can also use cbind() function to add the new column to the existing dataframe

>cbind(salaries, experience)

Hope this helps.


Just to add to your commands, you can names the columns as -

colnames(dataset_name) <- c("firstcol","secondcol".....)