首页 > 解决方案 > 如何使用表访问数据集的交集?

问题描述

我是 R 的初学者。

我有一张桌子 t,我想得到 P(gender|vote)。所以,我尝试了它直观的方式,print(t[gender][vote])。我这样做是因为我想获得 P(Yes|Female)。如果你能帮助这个初学者,那就太棒了。提前致谢。

x = read.csv2("./chilean_voting.csv",stringsAsFactors=FALSE,sep=",");

x[,5] = floor(x[,5]/10)

vote = 9;                           
education = 6;
gender = 4;
region = 1
age = 5;
region = 2;


t = table(x[,c(education,gender,age,region,vote)])

print(x[age])
print(t[age][gender])

https://repl.it/repls/EcstaticLowPaintprogram

标签: r

解决方案


推荐阅读