0

I have to run a t.test in R on the following: If the YearsAtCompany of Single is less than Married

Meaning somehow I need to compare the YearsatCompany with Marital Status

I have tried:

t.test(EmployeeAttrition$YearsAtCompany[Single],EmployeeAttrition$YearsAtCompany[Married],alternative = "less")

But that isn't giving me the information correctly. I am fairly new at R. And have researched other questions on here and still can't get the code right.

Sample data:

Data Screenshot

Kenzo_Gilead
  • 2,187
  • 9
  • 35
  • 60
TeaCup
  • 53
  • 1
  • 1
  • 7
  • Possible duplicate of [R multiple conditions in row selection of matrix](https://stackoverflow.com/questions/13762402/r-multiple-conditions-in-row-selection-of-matrix) – kabanus Oct 21 '17 at 17:53
  • Do **not** post data as images or graphic files, please edit your question and post the output of `dput(EmployeeAttrition)`. See [this](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and [this](https://stackoverflow.com/help/mcve). – Rui Barradas Oct 21 '17 at 18:56

1 Answers1

0

You can use with and properly subset your data (You needed to specific the variable in EmployeeAttrition to subset by).

with(EmployeeAttrition, t.test(YearsAtCompany[MaritalStatus == "Single"], YearsAtCompany[MaritalStatus == "Married"], alternative = "less")
Jake Kaupp
  • 7,892
  • 2
  • 26
  • 36