我有一个矩阵,我想用100乘以每个单元格,在它旁边插入"%“,最后有一个矩阵。
mtcars1 <- as.matrix(head(mtcars))
class(mtcars1)
mtcars1.per <- paste0(round(prop.table((mtcars1)), digits=2)*100, "%")以矩阵形式表示的预期结果:
# mpg cyl disp hp drat wt qsec vs am gear carb
#Mazda RX4 "1%" "0%" "7%" "5%" "0%" "0%" "1%" "0%" "0%" "0%" "0%"在此之前,非常感谢您。
发布于 2020-04-19 03:38:04
如果我们最后需要一个matrix,请确保赋值为[],以保留属性
mtcars1.per <- mtcars1
mtcars1.per[] <- paste0(round(prop.table((mtcars1)), digits=2)*100, "%")https://stackoverflow.com/questions/61295132
复制相似问题