Appending % sign in output of prop.table

后端 未结 4 491
囚心锁ツ
囚心锁ツ 2021-01-12 07:42

I\'m trying to append % sign in the output of prop.table to use in Sweave. My attempted code is below:

m <- matrix(1:4,2)
dimnam         


        
4条回答
  •  春和景丽
    2021-01-12 08:07

    Most functions designed to work with vectors also accept matrices but return a vector instead of a matrix: paste, sprintf, etc. You can use apply, that will return a matrix.

    apply( 
      prop.table(m,1)*100, 
      2, 
      function(u) sprintf( "%.1f%%", u ) 
    )
    

提交回复
热议问题