Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Changing column data types
5. Change column type
Basic data cleaning


You've probably figured out that as.factor() and as.character() are members of a family of functions that change element data types. This family has other members that convert to numeric (as.numeric()) and integer (as.integer()) data types, as well as others. Their use follows the exact same pattern we've already seen. For example, if we wanted to use the as.integer() function, we'd write:

dataset_name$column_name <- as.integer(dataset_name$column_name)


There is one more column in the survey data frame which we need to take care of: age – it has the wrong data type. Change age to numeric using the as.numeric() function.