如何基于R中的计数表生成比例表?

问题描述 投票:1回答:1

假设我有一个类似的计数表:

library(tidyverse)
set.seed(123)
df<-data.frame(x=letters[1:3],
                y=sample(1:10, 3),
                z=sample(3:20, 3))%>%
    mutate(tot=rowSums(select(., -1)))
df
  x  y  z tot
1 a  3 20  23
2 b 10 13  23
3 c  2  7   9

如何快速生成比例表,例如>

  x     y     z tot
1 a 13.04 86.96 100
2 b 43.48 56.52 100
3 c 22.22 77.78 100

假设我有一个计数表,例如:library(tidyverse)set.seed(123)df%mutate(tot = ...

r
1个回答
0
投票

这是您想要的吗?

© www.soinside.com 2019 - 2024. All rights reserved.