Question

Suppose you survey students regarding their sexual orientation, and code the results as 1=Hetrosexual, 2=Homosexual, 3=Bisexual,...

Suppose you survey students regarding their sexual orientation, and code the results as 1=Hetrosexual, 2=Homosexual, 3=Bisexual, 4=Asexual. Here is the data: 1 2 4 2 4 1 2 1 3 4 2 2 3 1 1 1 3 2 2 1 3 4 1 2 1 3 4 3 4 1 1 1 2 1 1 2 3 3 2 Assume you read in the data as an integer vector S. However, the numbers need to be treated as values of a categorical variable in further analysis. What should you do with S to facilitate this? Choose the most appropriate answer. Convert S to a data frame: S = as.data.frame(S) Convert S to a character vector Convert S to a vector of factors Leave it as is, and do no calculations

0 0
Add a comment Improve this question Transcribed image text
Answer #1

I guess in the last line 3 options are given and we have to choose the best option for treating it as categorical values.

so we will analyse all the best option.

Let us understand what is categorical values - generally we have two types of values one is continuous and other is categorical values, categorical values are those which have very limited values and belongs to a finite group.

in this case we have four values 1, 2, 3, 4

now analyse our options

first option is convert S to a data frame

here is the code:

S <- c(1, 2, 2, 4, 1, 2, 1, 3, 4, 2, 2, 3, 1, 1, 1, 3, 2, 2, 1, 3 ,4, 1, 2, 1, 3, 4, 3, 4, 1, 1, 1, 2, 1, 1, 2, 3, 3, 2)

print(S)
S = as.data.frame(S)
print(S)

here is the ss of the output:

option 2: convert to a character vector

here is the code:

S <- c(1, 2, 2, 4, 1, 2, 1, 3, 4, 2, 2, 3, 1, 1, 1, 3, 2, 2, 1, 3 ,4, 1, 2, 1, 3, 4, 3, 4, 1, 1, 1, 2, 1, 1, 2, 3, 3, 2)

print(S)
S <- as.character(S)
print(S)

here is the ss of the output:

option 3: convert S to a vector of factors

here is the code:

S <- c(1, 2, 2, 4, 1, 2, 1, 3, 4, 2, 2, 3, 1, 1, 1, 3, 2, 2, 1, 3 ,4, 1, 2, 1, 3, 4, 3, 4, 1, 1, 1, 2, 1, 1, 2, 3, 3, 2)

print(S)
S <- factor(S)
print(S)

here is the ss of the output:

Now as we can see that in the last output where we have converted to a factor in R , this shows levels means the categories.

actually in R factors are used to represent the categorical values .

so best answer to represent is using factors in R

I hope this will help you so please give positive ratings :))

Add a comment
Know the answer?
Add Answer to:
Suppose you survey students regarding their sexual orientation, and code the results as 1=Hetrosexual, 2=Homosexual, 3=Bisexual,...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Question 2 If you read in a csv file using read.csv() function into R, what is the resulting datastructure in which R st...

    Question 2 If you read in a csv file using read.csv() function into R, what is the resulting datastructure in which R stores the read-in data? A. numeric B. matrix    C. data.frame    D. vector    Question 3 Suppose you have 4 integers, 4 characters, and 4 logical values. Which datastructure can you use to store all 12 values? Choose one or more options. A. a vector B. a matrix C. a list D. a data frame Question 4 Suppose you have...

  • 1. What is the difference between heterosexism and homophobia? 2. Can homosexuals change their sexual orientation...

    1. What is the difference between heterosexism and homophobia? 2. Can homosexuals change their sexual orientation if they want to? And if 3. Why do researchers generally recommend using the term "sexual 4. Should discrimination based on sexual orientation be outlawed to the 5. If people believe in a literal interpretation of the Bible, is it prejudiced so, can heterosexuals do the same? orientation" rather than "sexual preference"? same extent as discrimination based on race and sex? for them to......

  • Choose 5 to answer 1) What is the difference between heterosexism and homophobla? 2) Can homosexuals...

    Choose 5 to answer 1) What is the difference between heterosexism and homophobla? 2) Can homosexuals change their sexual orientation if they want to? And if so, can heterosexuals do the same? And does it really matter? 3) Why do researchers generally recommend using the term "sexual orientation rather than "sexual preference"? 4) Should discrimination based on sexual orientation be outlawed to the same extent as discrimination based on race and sex? 5) If people believe in a literal interpretation...

  • 1) What are the difference between an asexual spore and sexual spore? 2) Is it possible...

    1) What are the difference between an asexual spore and sexual spore? 2) Is it possible to have positive EC tubes and negative BGB tubes for the same sample? explain. 3) What is the type of gas is collecting in the Durham tubes? 4) If our real concern is with fecal contamination and EC media confirms E. coli, why do you suppose we run the LTB and BGB parts of this test?

  • The Book of R (Question 20.2) Please answer using R code. Continue using the survey data...

    The Book of R (Question 20.2) Please answer using R code. Continue using the survey data frame from the package MASS for the next few exercises. The survey data set has a variable named Exer , a factor with k = 3 levels describing the amount of physical exercise time each student gets: none, some, or frequent. Obtain a count of the number of students in each category and produce side-by-side boxplots of student height split by exercise. Assuming independence...

  • In basic c develop the code below: (a) You will write a program that will do...

    In basic c develop the code below: (a) You will write a program that will do the following: prompt the user enter characters from the keyboard, you will read the characters until reading the letter ‘X’ You will compute statistics concerning the type of characters entered. In this lab we will use a while loop. We will read characters from stdin until we read the character ‘X’. Example input mJ0*5/]+x1@3qcxX The ‘X’ should not be included when computing the statistics...

  • In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the...

    In C code 1. Write and submit the algorithm OR flowchart to indicate you understand the problem 2. Create a project and name the source code lastname_firstname_prog5.c 3. Use the prog5.c as a guide, copy/ paste into your project source code *** build run and test, the outline code - You will need to declare an integer variable called again and initialize it 4. Add the function prototype and implement the function definition for the Greeting function 5. Add the...

  • 1. Do the following base conversions. (10 pts)       a. Convert the binary number 110100 to...

    1. Do the following base conversions. (10 pts)       a. Convert the binary number 110100 to decimal                                                                 b. Convert the decimal number 94 to hexadecimal                           c. Convert the binary number 10111011 to hexadecimal                             d. Convert the hexadecimal number B3 to binary                                   e. Convert the hexadecimal number 39E to binary                     2. The Starship Enterprise is visiting a planet where the inhabitants have 7 fingers. Not surprisingly, they use a...

  • Jeans Survey Suppose that young adults own an average of three pairs of jeans. Survey eight...

    Jeans Survey Suppose that young adults own an average of three pairs of jeans. Survey eight people from your class to determine if the average is higher than three. Assume the population is normal. The average numar of Teani fim fhe 'Survey /s 6.25 1. H 2. Н 3. In words, define the random variable. 4. The distribution to use for the test is 5. Determine the test statistic using your data. 6. Draw a graph and label it appropriately;...

  • Group #3 – Holiday Inn Orlando-Disney Springs has unusually high employee turnover 1) Comply 10 survey questions to uncover information regarding your company’s problem and/or objectives. In this assignment, identify the data that you will need to gain s

    Holiday inn Orlando disney spring s has unusually high employee turnover 1)comply 10 survey questions to uncover information regarding your company s problem and/or objectives .Inthe assignment, identify the data that you will need to gain some insight into  each scenario (10marks)what type of sample are you using ?Why?(1mark)-who Will be your sample ?Who will be in your survey ?Why?(1mark)for each survey  question -include an explanation as to why are asking this question.how does this question lead ti the information...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT