Reputation: 47
I have a text file of employee data that includes what raise the employee received, if the employee negotiated for the raise, and the gender of the employee. What I'm trying to do is create a histogram of the amount of a raise an employee received based on the gender of the employee and if they negotiated for the raise or not. When I run my code I keep getting this error: invalid number of 'breaks'. Could someone please show me where I went wrong.
Here's an example of the text file:
emp received negotiated gender year
25 12.5 TRUE F 2013
318 5.2 FALSE F 2013
417 9.8 FALSE M 2009
523 6.8 TRUE M 2009
1218 2.1 TRUE F 2009
2601 13.9 FALSE M 2006
2225 7.8 TRUE M 2006
3000 8.5 FALSE F 2006
Here's some minimal code for what I'm trying to do:
d<-read.csv("employees.txt", header=TRUE, sep="\t")
cat("\nDisplay what was loaded:")
str(d)
abline(m)
abline(mean(d$received), 0, lty=2)
hist(d$received[d$negotiated == TRUE && d$gender == '1'], main = 'Male Employees Who Negotiated Raises' )
dev.new()
hist(d$received[d$negotiated == TRUE && d$gender == '2'], main = 'Female Employees Who Negotiated Raises' )
Upvotes: 1
Views: 50338
Reputation: 193507
You have some problems in your syntax.
Note that you have converted gender to a factor
variable with values of "1" and "2" instead of "M" and "F". If you run your code line-by-line, I'll guess that it should work up to your last set of histograms.
Change those lines to:
hist(d$received[d$negotiated == TRUE & d$gender == 2],
main = 'Male Employees Who Negotiated Raises' )
hist(d$received[d$negotiated == TRUE & d$gender == 1],
main = 'Female Employees Who Negotiated Raises' )
Also, notice that I changed &&
to &
. Run d$negotiated == TRUE & d$gender == 2
and d$negotiated == TRUE && d$gender == 2
to see how they are different from each other.
Upvotes: 2