本文介绍了使功能适应潮汐生态系统的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Function box_m
当前要求其第一个参数不包括分组变量,而第二个参数仅是分组变量.例如: box_m(d [-1],d $ Group)
.
Function box_m
from library(rstatix)
currently requires that its first argument NOT include the grouping variable, and its second argument only be the grouping variable. For example: box_m(d[-1], d$Group)
.
我正在尝试重新编写此函数,以使 box_m2
可以像这样: box_m2(d,Group)
.
I'm trying to re-write this function such that box_m2
would work like: box_m2(d, Group)
.
我尝试了以下方法但没有成功,但想知道是否有办法实现我的目标?
I have tried the following without success but was wondering if there might be a way to achieve my goal?
library(rstatix)
library(tidyverse)
d <- read.csv("https://raw.githubusercontent.com/rnorouzian/v/main/memory.csv")[-1]
box_m(d[-1], d$Group) # How the function currently works
# box_m2(d, Group) # How I would like the function to work
# My trial without success to achieve `box_m2`:
box_m2 <- function(data, group){
dat <- dplyr::select(data, -vars(group))
box_m(dat, one_of(group))
}
# New function
box_m2(d, Group)
推荐答案
您可以借助curl-curly( {{}}
)运算符来编写函数.
You can write the function with the help of curly-curly ({{}}
) operator.
library(rstatix)
library(dplyr)
box_m2 <- function(data, group){
dat <- dplyr::select(data, -{{group}})
box_m(dat, data %>% pull({{group}}))
}
identical(box_m(d[-1], d$Group), box_m2(d, Group))
#[1] TRUE
这篇关于使功能适应潮汐生态系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!