[R] function problem: multi selection in one argument

PIKAL Petr petr@p|k@| @end|ng |rom prechez@@cz
Tue Jan 25 09:08:26 CET 2022


Hallo

You should explain better what do you want as many people here do not use 
tidyverse functions.

I am not sure what the function should do.
table(iris$Species)
give the same result and whatever you do in tidyverse part it always finalise 
in table(...$Species)

Cheers
Petr

> -----Original Message-----
> From: R-help <r-help-bounces using r-project.org> On Behalf Of Kai Yang via R-help
> Sent: Tuesday, January 25, 2022 1:14 AM
> To: R-help Mailing List <r-help using r-project.org>
> Subject: [R] function problem: multi selection in one argument
>
> Hello Team,
> I can run the function below:
>
> library(tidyverse)
>
> f2 <- function(indata, subgrp1){
>   indata0 <- indata
>   temp    <- indata0 %>% select({{subgrp1}}) %>% arrange({{subgrp1}}) %>%
>     group_by({{subgrp1}}) %>%
>     mutate(numbering =row_number(), max=max(numbering))
>   view(temp)
>   f_table <- table(temp$Species)
>   view(f_table)
>   return(f_table)
> }
> 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,
> Kai
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.


More information about the R-help mailing list