Closed Mzhuk7 closed 1 month ago
IMHO you have forgotten the dataset, h
in your case:
mutate(h, across(c("Fertility","Agriculture", "Examination","Education", "Catholic","Infant.Mortality"),scale))
h%>% mutate(across(c("Fertility","Agriculture", "Examination","Education", "Catholic","Infant.Mortality"),scale))
PS: I'm a simple user (ie not from the tidyverse team).
h<-tibble(
Fertility=1:5,
Agriculture=1:5,
Examination=1:5,
Education=1:5,
Catholic=1:5,
Infant.Mortality=1:5,
other1=1:5,
other2=1:5,
)
mutate(h,across(c("Fertility","Agriculture", "Examination","Education", "Catholic","Infant.Mortality"),scale))
results:
# A tibble: 5 × 8
Fertility[,1] Agriculture[,1] Examination[,1] Education[,1] Catholic[,1] Infant.Mortality[,1] other1 other2
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <int> <int>
1 -1.26 -1.26 -1.26 -1.26 -1.26 -1.26 1 1
2 -0.632 -0.632 -0.632 -0.632 -0.632 -0.632 2 2
3 0 0 0 0 0 0 3 3
4 0.632 0.632 0.632 0.632 0.632 0.632 4 4
5 1.26 1.26 1.26 1.26 1.26 1.26 5 5
@philibe is right
Brief description of the problem: In some of the old courses, I pass using this function from h: h_st <- mutate_each (h,"scale") Rstudio says that this function is obsolete. it suggests to use across. I've checked several sites and created the following function.
h_st <- mutate(across(c("Fertility","Agriculture", "Examination","Education", "Catholic","Infant.Mortality"),scale))
But Rstudio says the following: "Error in
across()
: ! Must only be used inside data-masking verbs likemutate()
,filter()
, andgroup_by()
" and I cannot understand the error here, because across is in "()".Can someone please help to solve this problem?