我有两个数据帧(矩阵)。我想过去或者将值加在一起,可能是通过添加括号。这是一个例子: 所以我有' x'和'。我想把它们结合起来,以便我有' z'。
set.seed(1)
x <- matrix(sample.int(6, size = 2*3, replace = TRUE), nrow = 2, ncol = 3)
y <- matrix(sample.int(6, size = 2*3, replace = TRUE), nrow = 2, ncol = 3)
z <- data.frame(c("2(6)", "3(4)"), c("4(4)", "6(1)"), c("2(2)", "6(2)"))
colnames(z) <- c("A1", "A2", "A3")
答案 0 :(得分:2)
你可以尝试:
matrix(paste0(x, "(",y,")"), dim(x), dimnames = list(NULL, paste0("A", 1:3)))
A1 A2 A3
[1,] "2(6)" "4(4)" "2(2)"
[2,] "3(4)" "6(1)" "6(2)"