【发布时间】:2021-07-21 01:06:52
【问题描述】:
我正在制作一些基本 R 使用的练习和演示文稿。前段时间,为了使用子集和访问对象中的不同元素,我制作了一个练习,即“尝试更改数组 X 中矩阵 1 的行和列的名称”。这是数组:
, , 1
[,1] [,2] [,3] [,4] [,5]
[1,] 0.5 0.5 0.5 0.5 0.5
[2,] 0.5 0.5 0.5 0.5 0.5
[3,] 0.5 0.5 0.5 0.5 0.5
[4,] 0.5 0.5 0.5 0.5 0.5
[5,] 0.5 0.5 0.5 0.5 0.5
, , 2
[,1] [,2] [,3] [,4] [,5]
[1,] 4.5 4.5 4.5 4.5 4.5
[2,] 4.5 4.5 4.5 4.5 4.5
[3,] 4.5 4.5 4.5 4.5 4.5
[4,] 4.5 4.5 4.5 4.5 4.5
[5,] 4.5 4.5 4.5 4.5 4.5
当时对我有用的解决方案是:
colnames(ArrayX[,, 1]) <- c(paste("coordX", 1:5, sep = ""))
rownames(ArrayX[,, 1]) <- c(paste("coordY", 1:5, sep = ""))
但是,现在,即使运行时没有返回错误,数组仍然保持不变......
这是会话信息:
R version 4.0.4 (2021-02-15)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)
Matrix products: default
locale:
[1] LC_COLLATE=Spanish_Spain.1252 LC_CTYPE=Spanish_Spain.1252 LC_MONETARY=Spanish_Spain.1252 LC_NUMERIC=C
[5] LC_TIME=Spanish_Spain.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] RODBC_1.3-17 knitr_1.31 readxl_1.3.1 reshape2_1.4.4 forcats_0.5.1 stringr_1.4.0 dplyr_1.0.5 purrr_0.3.4
[9] readr_1.4.0 tidyr_1.1.3 tibble_3.1.0 ggplot2_3.3.3 tidyverse_1.3.0
loaded via a namespace (and not attached):
[1] Rcpp_1.0.6 plyr_1.8.6 cellranger_1.1.0 pillar_1.5.1 compiler_4.0.4 dbplyr_2.1.0 tools_4.0.4
[8] jsonlite_1.7.2 lubridate_1.7.10 lifecycle_1.0.0 gtable_0.3.0 pkgconfig_2.0.3 rlang_0.4.10 reprex_1.0.0
[15] cli_2.3.1 rstudioapi_0.13 DBI_1.1.1 xfun_0.22 haven_2.3.1 withr_2.4.1 xml2_1.3.2
[22] httr_1.4.2 fs_1.5.0 generics_0.1.0 vctrs_0.3.6 hms_1.0.0 grid_4.0.4 tidyselect_1.1.0
[29] glue_1.4.2 R6_2.5.0 fansi_0.4.2 modelr_0.1.8 magrittr_2.0.1 backports_1.2.1 scales_1.1.1
[36] ellipsis_0.3.1 rvest_1.0.0 assertthat_0.2.1 colorspace_2.0-0 utf8_1.2.1 stringi_1.5.3 munsell_0.5.0
[43] broom_0.7.5 crayon_1.4.1
我很困惑,谢谢
【问题讨论】: