求两个变量之比的R函数

idfiyjo8  于 2023-05-15  发布在  其他
关注(0)|答案(1)|浏览(82)

我有一个包含三个不同变量的Excel文件数据集,我需要找出三个变量中两个变量的比率。拜托,我该怎么解决?我是编程新手!!!Non-Responders and Population Patient Count

zengzsys

zengzsys1#

花些时间学习如何提出社区可以帮助你的问题。
我希望这对你来说是一个很好的解决方案:

library(tidyverse)
df <- tibble(var1 = sample(1:100,20),
             var2 = sample(1:100,20),
             var3 = sample(1:100,20))

# Now let's use mutate to create a fourth column and define it as the ratio of var1 / var 2:

df %>% mutate(ratio1_2 = var1/var2) %>% 
  
# And also let's sort the table according to the ratios

arrange(ratio1_2)

相关问题