Luwis:
data <-
data.frame(
"Subgroup" = rep (1:2, c(10, 5)),
"Observation" = c(rnorm(14), NA)
)
data %>%
group_by(Subgroup) %>%
mutate("New variable" = Observation / mean(Observation, na.rm = TRUE),
GMean=mean(Observation, na.rm = TRUE))
You are right, I checked with R4.05 and R4.10 without using Rstudio and it is ok but when I run it via Rstudio I get a different result. My R sessionInfo from Rstudio is
sessionInfo()
R version 4.1.0 (2021-05-18)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=English_United States.1252 LC_CTYPE=English_United States.1252 LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C LC_TIME=English_United States.1252
attached base packages:
[1] grid stats graphics grDevices utils datasets methods base
other attached packages:
[1] doseResponse_0.0.1.8 minpack.lm_1.2-1 emmeans_1.6.2-1 data.table_1.14.0 msm_1.6.8 plyr_1.8.6
[7] drc_3.2-0 drcData_1.1-3 MASS_7.3-54 nlme_3.1-152 plotly_4.9.4.1 yardstick_0.0.8
[13] workflowsets_0.1.0 workflows_0.2.3 tune_0.1.6 rsample_0.1.0 recipes_0.1.16 parsnip_0.1.7
[19] modeldata_0.1.1 infer_0.5.4 dials_0.0.9 scales_1.1.1 tidymodels_0.1.3 broom_0.7.9
[25] forcats_0.5.1 dplyr_1.0.7 purrr_0.3.4 readr_2.0.0 tidyr_1.1.3 tibble_3.1.3
[31] tidyverse_1.3.1 kableExtra_1.3.4 knitr_1.33 pander_0.6.4 qdapRegex_0.7.2 stringr_1.4.0
[37] readxl_1.3.1 egg_0.4.5 ggplot2_3.3.5 gridExtra_2.3 gtable_0.3.0
loaded via a namespace (and not attached):
[1] backports_1.2.1 systemfonts_1.0.2 lazyeval_0.2.2 splines_4.1.0 listenv_0.8.0 TH.data_1.0-10 digest_0.6.27
[8] foreach_1.5.1 htmltools_0.5.1.1 fansi_0.5.0 magrittr_2.0.1 tzdb_0.1.2 openxlsx_4.2.4 globals_0.14.0
[15] modelr_0.1.8 gower_0.2.2 sandwich_3.0-1 svglite_2.0.0 hardhat_0.1.6 colorspace_2.0-2 rvest_1.0.1
[22] haven_2.4.2 xfun_0.24 crayon_1.4.1 jsonlite_1.7.2 survival_3.2-11 zoo_1.8-9 iterators_1.0.13
[29] glue_1.4.2 ipred_0.9-11 webshot_0.5.2 car_3.0-11 abind_1.4-5 mvtnorm_1.1-2 DBI_1.1.1
[36] Rcpp_1.0.7 plotrix_3.8-1 xtable_1.8-4 viridisLite_0.4.0 GPfit_1.0-8 foreign_0.8-81 lava_1.6.9
[43] prodlim_2019.11.13 htmlwidgets_1.5.3 httr_1.4.2 ellipsis_0.3.2 farver_2.1.0 pkgconfig_2.0.3 nnet_7.3-16
[50] dbplyr_2.1.1 utf8_1.2.2 labeling_0.4.2 tidyselect_1.1.1 rlang_0.4.11 DiceDesign_1.9 munsell_0.5.0
[57] cellranger_1.1.0 tools_4.1.0 cli_3.0.1 generics_0.1.0 evaluate_0.14 yaml_2.2.1 fs_1.5.0
[64] zip_2.2.0 future_1.21.0 xml2_1.3.2 compiler_4.1.0 rstudioapi_0.13 curl_4.3.2 reprex_2.0.0
[71] lhs_1.1.1 stringi_1.7.3 highr_0.9 lattice_0.20-44 Matrix_1.3-4 vctrs_0.3.8 pillar_1.6.2
[78] lifecycle_1.0.0 furrr_0.2.3 estimability_1.3 R6_2.5.0 rio_0.5.27 parallelly_1.27.0 codetools_0.2-18
[85] gtools_3.9.2 assertthat_0.2.1 withr_2.4.2 multcomp_1.4-17 expm_0.999-6 parallel_4.1.0 hms_1.1.0
[92] rpart_4.1-15 timeDate_3043.102 coda_0.19-4 class_7.3-19 rmarkdown_2.9 carData_3.0-4 pROC_1.17.0.1
[99] lubridate_1.7.10