我有以下数据:
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#> filter, lag
#> The following objects are masked from 'package:base':
#>
#> intersect, setdiff, setequal, union
set.seed(1)
df <- data_frame(
genes = paste("Gene_",letters[0:10],sep=""),
X = rnorm(10, 0, 1),
Y = rnorm(10, 0, 2),
Z = rnorm(10, 0, 4))
df
#> # A tibble: 10 × 4
#> genes X Y Z
#> <chr> <dbl> <dbl> <dbl>
#> 1 Gene_a -0.6264538 3.02356234 3.6759095
#> 2 Gene_b 0.1836433 0.77968647 3.1285452
#> 3 Gene_c -0.8356286 -1.24248116 0.2982599
#> 4 Gene_d 1.5952808 -4.42939977 -7.9574068
#> 5 Gene_e 0.3295078 2.24986184 2.4793030
#> 6 Gene_f -0.8204684 -0.08986722 -0.2245150
#> 7 Gene_g 0.4874291 -0.03238053 -0.6231820
#> 8 Gene_h 0.7383247 1.88767242 -5.8830095
#> 9 Gene_i 0.5757814 1.64244239 -1.9126002
#> 10 Gene_j -0.3053884 1.18780264 1.6717662
我可以这样计算列 X:
fit_X <- MASS::fitdistr(df$X,"normal")
broom::tidy(fit_X)
#> term estimate std.error
#> 1 mean 0.1322028 0.2341758
#> 2 sd 0.7405289 0.1655873
broom::glance(fit_X)
#> n logLik AIC BIC
#> 1 10 -11.18548 26.37096 26.97613
我怎样才能对所有列(除了第一个 - genes
)执行此操作,以便最终我得到:
mean.estimate sd.estimate mean.stderror sd.stderror n loglik AIC BIC
X 0.1322028 0.7405289 0.2341758 0.1655873 10 -11.18548 26.37096 26.97613
Y 0.4976899 2.0292617 0.6417089 0.4537 10 -21.26611 46.53221 47.13738
Z -0.534693 3.626276 1.1467291 0.8108599 10 -27.07145 58.14289 58.74806