Browsed by
Tag: Data Analysis Tips

Renaming Variables and Character Strings in R

Renaming Variables and Character Strings in R

I want to show you how to rename variables and character strings in R. This is a basic task but one that I do frequently when working with a new dataset. Renaming variables and character strings is useful, especially when creating graphics. For example, if I were plotting these data, I would want the variable name to show as “Coffee Roast” rather than “coffee.” If I were just doing data wrangling, I wouldn’t care as much about the variable name….

Read More Read More

Stata to R: How to Tabulate a Categorical Variable

Stata to R: How to Tabulate a Categorical Variable

When working with a data set, one of the first things I do is look at the count and relative frequency of categorical variables of interest. In Stata, this is relatively straight forward with the tab command. In R, however, it isn’t quite as straight forward, but still possible. The equivalent code in R, is: dataset %>% group_by(var) %>% summarise(n = n()) %>% mutate(totalN = (cumsum(n)), percent = round((n / sum(n)), 3), cumpercent = round(cumsum(freq = n / sum(n)), 3))…

Read More Read More