Question

How do you convert categorical data to numerical data in R? My categorical explanatory variable is...

How do you convert categorical data to numerical data in R? My categorical explanatory variable is gender and my numerical is height. I want to make a boxplot for the relationship between them. When I go to make a boxplot using this:

aces$genderF <-factor(aces$gender,labels=c("male","female"))

boxplot(aces$height_cm-aces$genderF)

I get an error.

Homework Answers

Answer #1
  1. You are using '$' sign in naming the object so I hope you have a data frame named 'aces'. If you have no data frame then remove the '$' sign and use '_' to name the object.
  2. In 'aces$genderF' use 'levels' instead of 'labels' . Because 'labels' will change male to female and female to male.
  3. In boxplot command use '~' instead of '-' to define a relationship. Or if you have only 2 variable then you can use ',' also.

These are the errors which I have found. Try this.

If you still get error ,feel free to ask your query.

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Cortland Software, Inc. surveyed a sample of its programmers and recorded the following data on their:...
Cortland Software, Inc. surveyed a sample of its programmers and recorded the following data on their: age, gender, years of programming experience, whether or not they have a master’s degree, and annual salary. ​ Programmer ​ Age ​ Gender Years of Experience Master’s Degree ​ Salary 1 32 Male 8 No $59,450 2 27 Male 2 Yes 62,750 3 31 Female 6 Yes 65,820 4 37 Males 5 No 54,620 5 29 Female 5 Yes 61,900 6 25 Female 4...
*HOW WOULD I SET THIS UP IN A CHI-SQUARE TEST* An example for numerical to categorical...
*HOW WOULD I SET THIS UP IN A CHI-SQUARE TEST* An example for numerical to categorical data off the top of my head: Light of different color has different wavelengths, but certain ranges of wavelengths qualify as certain shades/hues/tints/etc. You can generalize and say a certain range can be called "blue" or "red". Red is usually attributed to light that has a wavelength between 780 and 622 nanometers, whereas blue light is between 492 and 455 nm. To the average...
I am reading in a CSV file (using R). When I first check if there are...
I am reading in a CSV file (using R). When I first check if there are any NA's there are none. I then clean my data and convert my Income variable from num to factor by using this code to discretize income by equal-width bins: min_income <- min(bd$income) max_income <- max(bd$income) bins = 3 width=(max_income - min_income)/bins; bd$income = cut(bd$income, breaks=seq(min_income, max_income, width)) When I complete cleaning/updating my data and check again for NA's I receive one. It is specific...
On the textbook's companion website click on Data for Empirical Exercises and Test Bank (Updated Edition)...
On the textbook's companion website click on Data for Empirical Exercises and Test Bank (Updated Edition) , you will find the data file Earnings_and_H eight, which contains data on earnings, height, and other characteristics of a random sample of U.S. workers. Run a regression of Earnings on Height using data for male workers only. First input the data into S TATA . Before you run the regression, use the f ollowing STATA command to drop the fe male workers from...
4) Suppose you want to find out if there is a relationship between anxiety and sleep...
4) Suppose you want to find out if there is a relationship between anxiety and sleep deprivation. So you go out and find 7 people and measure how much anxiety they are experiencing in their lives and how many hours of sleep they are getting. Let X be the explanatory variable to describe anxiety, you obtain the following values for X in order from subject 1 to subject 7: 1, 2, 4, 4, 5, 8, 7 Let Y be the...
Student # Gender Height Shoe Age Hand 1 F 68 8.5 20 R 2 F 60...
Student # Gender Height Shoe Age Hand 1 F 68 8.5 20 R 2 F 60 5.5 27 R 3 F 64 7 31 R 4 F 67 7.5 19 R 5 F 65 8 20 R 6 F 66 9 29 R 7 F 62 9.5 30 L 8 F 63 8.5 18 R 9 F 60 5 19 L 10 F 63 7.5 42 R 11 F 61 7 20 R 12 F 64 7.5 17 R 13...
Question 1: The data table shows the sugar content of a fruit (Sugar) for different numbers...
Question 1: The data table shows the sugar content of a fruit (Sugar) for different numbers of days after picking (Days). Days Sugar 0 7.9 1 12.0 3 9.5 4 11.3 5 11.8 6 10.3 7 4.2 8 0.8 HAND CALCULATIONS: The dependent (Y) variable is sugar content and the independent (X) variable is number of days after picking (Days). Do the following by hand, SHOWING WORK. You may use SAS/R to check your answers if you want. (a) Find...
2) Now read the following data into R. Use R for all statistical procedures. Sample Sample...
2) Now read the following data into R. Use R for all statistical procedures. Sample Sample A B 0.7969 1.4731 1.2669 3.2137 1.5856 2.2486 0.4959 1.1156 0.5022 10.6207 0.5524 1.9835 10.3060 31.2243 0.6244 3.7984 1.9789 1.4710 1.6788 9.0351 (a) Make q-q plots of both samples. (b) Perform a t-test (unequal variances). (c) Perform a MWU test. (d) Which test gave you the better p-value now? Why? (e) What is a “better” p-value? Why? 3) You measure the length of 5...
Data needs to be analyzed For this assignment I have to analyze the regression (relationship between...
Data needs to be analyzed For this assignment I have to analyze the regression (relationship between 2 independent variables and 1 dependent variable). Below is all of my data and values. I need help answering the questions that are at the bottom. Questions regarding the strength of the relationship   Sum of X1 = 184.6 Sum of X2 = 21307.03 Sum of Y = 2569.1 Mean X1 = 3.6196 Mean X2 = 417.7849 Mean Y = 50.3745 Sum of squares (SSX1)...
(9) 1- You want to test whether soil nitrogen content predicts plant height, so you measure...
(9) 1- You want to test whether soil nitrogen content predicts plant height, so you measure nitrogen in the soil and plant heights from throughout Ōtautahi/Christchurch. You run a regression and have this resultant ANOVA table. What is the F value for the model? df Sum of squares Mean Squares Model 1 7.4667 7.4667 Error 8 8.5783 1.0723 Select one: a. 1.148874 b. 0.8704172 c. 0.143611 d. 6.963257 2- The Pearson correlation coefficient r : Select one: a. Gives the...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT