繁体   English   中英

在 R 中创建一个表来总结结果

[英]Create a table in R to summarize outcome

我有一个包含以下数据的数据框( movement ): displVolumCat2perc_DVHT_99 , motion

“displ”包含:0.5mm、1.0mm、1.5mm “perc_DVHT_99 包含:我想总结的变量 bij 中位数(1st Qu.、3rd Qu.)“volumCat2”包含:a、b1、b2、c、d , e“运动”包含:旋转平移

我想创建一个汇总表,如下所示:

dput(setXY[1:10,])

structure(list(displ = c("0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm", 
"0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm"), 
    perc_DVH = c(99.169574073565, 98.3998642978761, 99.3452539098338, 
    98.3301531618343, 97.8633859305831, 97.572227542085, 99.3287258697977, 
    99.3033293087417, 95.287598273786, 97.0386976259169), VolumCat2 = c("e", 
    "e", "e", "e", "b1", "b1", "b1", "b1", "b1", "b1"), movement = c("t", 
    "t", "t", "t", "t", "t", "t", "t", "t", "t")), row.names = c(NA, 
-10L), class = c("tbl_df", "tbl", "data.frame"))

如何在 R 中创建它?

谢谢

使用答案,我能够创建 4 个看起来像的表在此处输入图像描述 但是我怎样才能改变平移和旋转的position。 我希望翻译的结果高于旋转的结果。 以及如何将(1st Qu.,3rd QU.)放在中值下方?

谢谢

以下是中位数的答案:

# load some helper packages
library(tidyverse)

# your dataframe
df <- structure(list(displ = c("0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm", 
"0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm", "0,5 mm"), 
    perc_DVH = c(99.169574073565, 98.3998642978761, 99.3452539098338, 
    98.3301531618343, 97.8633859305831, 97.572227542085, 99.3287258697977, 
    99.3033293087417, 95.287598273786, 97.0386976259169), VolumCat2 = c("e", 
    "e", "e", "e", "b1", "b1", "b1", "b1", "b1", "b1"), movement = c("t", 
    "t", "t", "t", "t", "t", "t", "t", "t", "t")), row.names = c(NA, 
-10L), class = c("tbl_df", "tbl", "data.frame"))

# now, we take the dataframe and then...
df %>%
    # ...for each combination of movement, displ and VolumCat2...
    group_by(movement, displ, VolumCat2) %>%
    # we calculate the median which gives us a long dataframe with only one column for the medians
    summarise(perc_median = median(perc_DVH)) %>%
    # and now we leave movement and displ as rows, but put VolumCat2 into rows
    pivot_wider(id_cols = c("movement", "displ")
                , names_from = VolumCat2
                , values_from = perc_median)

如果我们现在想为第 1 和第 3 个四分位数创建相同的值,我们只需将median(perc_DVH)替换为quantile(perc_DVH, probs = 0.25)quantile(perc_DVH, probs = 0.75)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM