gsub Function in R - Converting Revenue Data to Numeric
Автор: Daniel Bonneau
Загружено: 2022-06-24
Просмотров: 1903
Revenue data is often tracked with special characters, namely dollar signs and commas. While this is great for visually representing the data, it's not so great when we try to run numeric calculations on that revenue data.
You may think we can just use as numeric in r (as.numeric() function), but if the variable you're trying to convert to a number includes those dollar signs and commas, you'll just be left with NA values.
In this video, I show the use of the handy gsub() function to remove characters from variables in R. After doing that, we can then run our as.numeric() function as usual and convert our revenue data to a numeric.
While this example uses a simple revenue data set, it can be applied across the board, whenever you need to remove characters - even if you don't plan on converting to a numeric value later!
Finally, we combined it all into one statement inside of dplyr to help make our R code more compact and more readable.
Доступные форматы для скачивания:
Скачать видео mp4
-
Информация по загрузке: