Updating in R with mutate


Are you needing to make some changes to your data frame in R language? Perhaps you need to add a column that displays a calculation based on two or more other columns. R Markdown files are designed to be used with the rmarkdown package. rmarkdown comes installed with the RStudio IDE.

Here’s an example of the mutate function. It takes the existing column called carat in the data frame diamonds and creates a new column that has the values from carat multiplied by 100. mutate() always adds new columns at the end of your dataset. You won’t lose any columns with mutate.

mutate(diamonds, carat_2 = carat * 100)

If we want to multiply a column by 100, the syntax would be mutate(data_frame, new_column = existing_column * 100).

Leave a Reply