library(dplyr)
# Replaces original variable
data <-
data %>%
group_by(group) %>%
mutate_all(scale)
# Creates new "var_scaled" variables
data <-
data %>%
group_by(group) %>%
mutate_all(list(scaled = scale))
For completeness, if you don't want to scale() every variable, you can choose a select few...
data <-
data %>%
group_by(group) %>%
mutate_at(vars(var1, var2, var4), scale)
data <-
data %>%
group_by(group) %>%
mutate_at(vars(var1, var2, var4), list(scaled = scale))
data<-
data %>%
group_by(group)
Error in data %>% group_by(group) : could not find function "%>%"
mutate_all(scale)
Error in mutate_all(scale) : could not find function "mutate_all"
group_by(group)
Error in UseMethod("group_by_") :
no applicable method for 'group_by_' applied to an object of class "c('matrix', 'double', 'numeric')"
mutate_all(scale)
Error in UseMethod("tbl_vars") :
no applicable method for 'tbl_vars' applied to an object of class "function"
When you transpose your data you have coerced it to a matrix. The code I provided won't work on a matrix, it is meant for a data.frame or tbl_df. You need to make your data a data frame again with as.data.frame() or as_tibble(). My preference is for as_tibble().
Yes, when you transpose your data with t() you can lose important information because a matrix does not adhere to the same principles as a data frame. I advise against using t() on your data. There are other ways to re-structure your data.
Do you believe your data is being read incorrectly into R? What does it look like in Excel? Perhaps there is a parsing issue. It is difficult to offer specific advice without knowing/having access to the data.
Sharing the data would go a long way to helping troubleshoot your issue. You can send it to me privately if you aren't willing/allowed to share it publicly.