Question: use the R , data from http://www-bcf.usc.edu/ ~gareth/ISL/College.csv (a) Create a new qualitative variable, called Elite, by binning the Top10perc variable. We are going to
use the R , data from http://www-bcf.usc.edu/ ~gareth/ISL/College.csv

(a) Create a new qualitative variable, called Elite, by binning the Top10perc variable. We are going to divide universities into two groups based on whether or not the proportion of students coming from the top 10 % of their high school classes exceeds 50 % Elite-rep (O,nrow (college)) Elite[college$Top10perc >50]-1 (b) Use the ifelse() command to calculate a variable Elite2, which should be indentical to Elite. Elite2-ifelse command here (c) Use a for loop, and the indentical to Elite if(condition)fstatement 1} else fstatement 2/ construct, to define a variable Elite3, which should be N-dim(college) [1] Elite3-rep (NA,N) for (i in 1:N) if(college$Top10perc[i] >50) assign Elite3[i] here else fassign Elite3[i] hereh (d) Use the table command to create two way frequency tables of Elite vs Elite2 and Elite vs Elite3. Then print the tables table (Elite,Elite2) table (Elite,Elite3) Do the three variables carry the same information? (e) There are subtle difference in the way that character and factor variables are treated. Use an ifelse() statement to define a character variable Elitec which takes the value "Yes" if the school is an elite school, and otherwise "No". Then convert the character variable to a factor variable, using the command Elitef-as.factor(Elitec). Use the command "table(Elitec,Elitef)" to see if the character and factoir variables carry the same information. Use the summary() function on each of Elitec and Elitef to see if they are treated the same. Similarly, use borplot (Outstate-Elitef) and/or boxplot(Outstate-Elitec) to see whether boxplot() accommodates character and/or factor variables Elitec-ifelse command here Elitef-as.factor (Elitec) make a two way table here summary (Elitec) summary (Elitef) Do Elitec and Elitef carry the same information? Do the summary) and boxplot) functions work with the character form! boxplot (Outstate-Elitef) boxplot (Outstate-Elitec) (f) To further explore the if) elsesf" construct, try the following: "if(collegeSTop10perc>50) {Elite4-1) else {Elite4-0 if(college$Top10perc>50) Elite4-1} else {Elite4-0 Elite4 What went wrong? Explore the help info on ifelse and if. Better yet, make up some of your own examples to see how they work. How do the ifelse() and if)1 else s/ constructs differ? (a) Create a new qualitative variable, called Elite, by binning the Top10perc variable. We are going to divide universities into two groups based on whether or not the proportion of students coming from the top 10 % of their high school classes exceeds 50 % Elite-rep (O,nrow (college)) Elite[college$Top10perc >50]-1 (b) Use the ifelse() command to calculate a variable Elite2, which should be indentical to Elite. Elite2-ifelse command here (c) Use a for loop, and the indentical to Elite if(condition)fstatement 1} else fstatement 2/ construct, to define a variable Elite3, which should be N-dim(college) [1] Elite3-rep (NA,N) for (i in 1:N) if(college$Top10perc[i] >50) assign Elite3[i] here else fassign Elite3[i] hereh (d) Use the table command to create two way frequency tables of Elite vs Elite2 and Elite vs Elite3. Then print the tables table (Elite,Elite2) table (Elite,Elite3) Do the three variables carry the same information? (e) There are subtle difference in the way that character and factor variables are treated. Use an ifelse() statement to define a character variable Elitec which takes the value "Yes" if the school is an elite school, and otherwise "No". Then convert the character variable to a factor variable, using the command Elitef-as.factor(Elitec). Use the command "table(Elitec,Elitef)" to see if the character and factoir variables carry the same information. Use the summary() function on each of Elitec and Elitef to see if they are treated the same. Similarly, use borplot (Outstate-Elitef) and/or boxplot(Outstate-Elitec) to see whether boxplot() accommodates character and/or factor variables Elitec-ifelse command here Elitef-as.factor (Elitec) make a two way table here summary (Elitec) summary (Elitef) Do Elitec and Elitef carry the same information? Do the summary) and boxplot) functions work with the character form! boxplot (Outstate-Elitef) boxplot (Outstate-Elitec) (f) To further explore the if) elsesf" construct, try the following: "if(collegeSTop10perc>50) {Elite4-1) else {Elite4-0 if(college$Top10perc>50) Elite4-1} else {Elite4-0 Elite4 What went wrong? Explore the help info on ifelse and if. Better yet, make up some of your own examples to see how they work. How do the ifelse() and if)1 else s/ constructs differ
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
