1

次のマトリックスがあります。

> dat

       [,1]      [,2]       [,3]        [,4]
foo 0.7574657 0.2104075 0.02922241 0.002705617
foo 0.0000000 0.0000000 0.00000000 0.000000000
foo 0.0000000 0.0000000 0.00000000 0.000000000
foo 0.0000000 0.0000000 0.00000000 0.000000000
foo 0.0000000 0.0000000 0.00000000 0.000000000
foo 0.0000000 0.0000000 0.00000000 0.000000000

これを考えると:

> new_names <- c("f0","f1","f2","f3","f4","f5");
# where the length of new_names matches the number of rows in the dat matrix

どうすればこれを入手できますか?

        [,1]      [,2]       [,3]        [,4]
f0 0.7574657 0.2104075 0.02922241 0.002705617
f1 0.0000000 0.0000000 0.00000000 0.000000000
f2 0.0000000 0.0000000 0.00000000 0.000000000
f3 0.0000000 0.0000000 0.00000000 0.000000000
f4 0.0000000 0.0000000 0.00000000 0.000000000
f5 0.0000000 0.0000000 0.00000000 0.000000000
4

2 に答える 2

4

たぶん、このようなものですか?

dat <- matrix(c(c(0.7574657, 0.2104075, 0.02922241, 0.002705617), rep(0, 4*6-4)), ncol = 4, nrow = 6, byrow = TRUE)

rownames(dat) <- paste0("f", seq(0, nrow(dat)-1))

名前のベクトルが既にある場合は、

rownames(dat) <- new_names
于 2012-05-15T09:44:26.433 に答える