# PROGRAMMING EXERCISE #1 # Use the sample() function to create a random sample # of size n = 500 college majors # by sampling with replacement # from a vector containing the following choices: # "Business", "Data Analytics", "History" and "Biology" # Save this random sample in an object called majors ?sample() sample(x, n = 500, replace = TRUE) { } # Use any appropriate R function to find the class # of the variable, majors. # Change the class of the object, majors, to factor # What are the levels for the factor, majors? ?levels() # Display the first 6 lines of the object, majors ?head() # Create a frequency table for the factor, majors. ?table()
#
The R code is given below with output screenshot
Step by step
Solved in 4 steps with 2 images