我有以下内容:
print(strategy_reallocations)
1 13 17
A "B" "C" "D"
print(dimnames(strategy_reallocations))
[[1]]
[1] "A"
[[2]]
[1] "B" "C" "D"
print(is.character(strategy_reallocations))
[1] TRUE
我想向这个角色添加另一个元素,使其看起来像:
0 1 13 17
A "Z" "B" "C" "D"
我在 G 上找不到正确的答案。到目前为止我尝试过的是,
strategy_reallocations <- c("Z", strategy_reallocations)
但这破坏了字符的数据结构。
print(strategy_reallocations)
[1] "Z" "B" "C" "D"
我怎样才能做到这一点?
编辑:
str(strategy_reallocations)
chr [1, 1:3] "B" "C" "D"
- attr(*, "dimnames")=List of 2
..$ : chr "A"
..$ : chr [1:3] "1" "13" "17"