我有以下矩阵:
> 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