R中运行T.Test比较两个不同的列
问题描述:
我必须在以下运行R A t.test: 如果是单身的YearsAtCompany低于已婚R中运行T.Test比较两个不同的列
意义不知何故,我需要比较YearsatCompany与婚姻状况
我曾尝试:
t.test(EmployeeAttrition$YearsAtCompany[Single],EmployeeAttrition$YearsAtCompany[Married],alternative = "less")
但是,这是不正确给我的信息。我在R方面相当新颖,并且在这里研究了其他问题,仍然无法获得正确的代码。
的样本数据:
答
您可以使用with
并正确子集数据(你需要在特定的EmployeeAttrition通过可变向子集)。
with(EmployeeAttrition, t.test(YearsAtCompany[MaritalStatus == "Single"], YearsAtCompany[MaritalStatus == "Married"], alternative = "less")
+0
而且工作:)真的很感激它! – TeaCup
+0
如果有帮助,请随时接受它作为答案。 –
的[在矩阵的行选择r多个条件]可能的复制(https://*.com/questions/13762402/r-multiple-conditions-in-row-selection-of-matrix) – kabanus
待办事项**不**将数据发布为图像或图形文件,请编辑您的问题并发布'dput(EmployeeAttrition)'的输出。请参阅[this](https://*.com/questions/5963269/how-to-make-a-great-r-reproducible-example)和[this](https://*.com/help/mcve) 。 –