[R] function problem: multi selection in one argument

Kai Yang y@ngk@|9999 @end|ng |rom y@hoo@com
Tue Jan 25 01:14:07 CET 2022

Hello Team,
I can run the function below:


f2 <- function(indata, subgrp1){
  indata0 <- indata
  temp    <- indata0 %>% select({{subgrp1}}) %>% arrange({{subgrp1}}) %>% 
    group_by({{subgrp1}}) %>%
    mutate(numbering =row_number(), max=max(numbering))
  f_table <- table(temp$Species)
f2(iris, Species)

You can see the second argument I use Species only, and it works fine. 
But If I say, I want the 2nd argument = Petal.Width, Species , how should I write the argument? I did try f2(iris, c(Petal.Width, Species)), but I got error message:
Error: arrange() failed at implicit mutate() step. 
* Problem with `mutate()` column `..1`.
i `..1 = c(Petal.Width, Species)`.
i `..1` must be size 150 or 1, not 300.

I'm not sure how to fix the problem either in function or can fix it when using the function.
Thank you,
	[[alternative HTML version deleted]]

More information about the R-help mailing list