I want to standardize some of my columns in my DF by year. I think I am grouping and selecting my variables correctly (in this example the variables that end in either ABC or XYZ), but am getting tied up using the mutate function. Here is my DF:
DF:
VARTY VARDCE Year Var1ABC VAr2XYZ VAR3ABC VAR4XYZ
38 67 2015 78 34 68 98
42 75 2013 85 56 87 75
56 87 2017 67 72 98 76
84 82 2018 78 34 91 89
etc-----
I would like to have:
DF:
VARTY VARDCE Year Var1ABC VAr2XYZ VAR3ABC VAR4XYZ Var1ABCZScore VAr2XYZZScore...
38 67 2015 78 34 68 98 1.2 0.7
42 75 2013 85 56 87 75 0.4 1.3
56 87 2017 67 72 98 76 -0.2 0.8
84 82 2018 78 34 91 89 0.6 0.1
etc-----
This is the code I am using:
DF.New<-DF%>%
group_by(Year)%>%
select(contains(c("ABC", "XYZ")))%>%
mutate(funs(scale))
Any help is appreciated!