计算 R 中的百分比

calculate percentage in R

我是R的初学者,R对我来说其实只是分析统计数据的手段,离程序员还很远。我需要一些帮助来构建 Excel sheet 变量的百分比。我需要 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还是不行。有人可以给我提示吗?

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

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

希望对您有所帮助。