【发布时间】:2020-11-01 08:41:39
【问题描述】:
我正在尝试更改 tibble 中的 rownames,该 tibble 由下面的 purrr 包中的 map_dfr 循环函数输出,但未成功。有解决办法吗?
foo <- function(x){
total <- rbinom(1, x, .5)
fixed <- total - 2
random <- fixed + 3
c(total = total, fixed = fixed, random = random)
}
m <- purrr::map_dfr(.x = c(6:9), .f = foo) # loop and output a tibble (a data.frame)
rownames(m) <- paste0("m", 1:4) # change the rownames
m
但是rownames不要改变:
# A tibble: 4 x 3
total fixed random
* <dbl> <dbl> <dbl>
1 2 0 3
2 3 1 4
3 4 2 5
4 2 0 3
【问题讨论】:
标签: r loops dataframe tidyverse