计算R中的百分比

时间:2016-06-01 18:09:29

标签: r dataframe percentage

我是R的初学者,R对我来说实际上只是分析我的统计数据的手段,所以我远不是一个程序员。我需要一些帮助,从Excel工作表中构建变量的百分比。我需要R.total和R.Max作为100%的基础。这就是我所做的:

DB <- read_excel("WechslerData.xlsx", sheet=1, col_names=TRUE, 
                 col_types=NULL, na="", skip=0) 

我想使用prop.table 但这不适用于我。比我试图制作数据框

R.total <- DB$R.total 
R.max <- DB$R.max 
DB.rus <- data.frame(R.total, R.max) 

prop.table仍无效。有人可以给我一个暗示吗?

1 个答案:

答案 0 :(得分:0)

不确定你想要什么,但对于这个模拟数据。

r.total <- runif(100,min=0, max=.6) # generate random variable
r.max <- runif(100,min=0.7, max=1)  # generate random variable
df <- data.frame(r.total, r.max) # create mock data frame

你可以尝试

# create a new column which is the r.total percentage of r.max
df$percentage <- df$r.total / df$r.max

希望它有所帮助。

相关问题