Change Data Types Using R
Explore how to change data types in R data frames efficiently using the mutate() function from the dplyr package. Learn to update or create columns, apply sequential transformations in pipelines, and convert continuous data into categories using the cut() function. Understand binning methods to simplify data interpretation in data cleaning tasks.
We'll cover the following...
Change data types in data frames
The dplyr package helps us apply the conversions in data frames without breaking data structures.
This lesson shows how we can specifically utilize the mutate() function in data conversions.
We can use it to update a column or create new columns. The pipeline function allows us to do it in a puzzle-like structure.
The mutate() function takes two default variables: the variable/column name to be modified and the process. If the variable name already exists, the existing column is updated. Otherwise,
a new column is created.
<data> <- mutate(<column> = as.<datatype>(<column>)) # Syntax structure
We update the conc and state columns ...