【发布时间】:2021-05-22 23:31:58
【问题描述】:
来自library(rstatix) 的函数box_m 目前要求它的第一个参数不包括分组变量,而它的第二个参数只能是分组变量。例如:box_m(d[-1], d$Group)。
我正在尝试重新编写此函数,以便 box_m2 的工作方式类似于:box_m2(d, Group)。
我尝试了以下方法但没有成功,但想知道是否有办法实现我的目标?
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)
【问题讨论】:
-
愿你分享一些可重现的预期输出,以便更容易理解你试图解决的“问题”。从您分享的内容中,我可以想到几种方案和解决方法,但我不确定我的理解是否与您的相符
标签: r function dataframe dplyr tidyverse