USArrests data frame to tibble with scaling in R

152 Views Asked by At

I'm working with the builtin USArrests data frame and I'm trying to scale as well as create a new column called state and make all state names lowercase. So far I can only either scale or create a new column with lowercase, but not both. Can someone help?

  scale(USArrests)
  arrest <- tibble::rownames_to_column(USArrests, "state")
  arrest$state = tolower(arrest$state)
  head(arrest)
1

There are 1 best solutions below

0
On

Your code scale(USArrests) is not saving the results anywhere. Just save it with a new name.

df <- as.data.frame(scale(USArrests))
arrest <- tibble::rownames_to_column(df, "state")
arrest$state = tolower(arrest$state)
head(arrest)