Question: My code doesn't work. Please tell me what I am doing wrong. I am using RStudio Directions: 1. In R, create two data frames for

My code doesn't work. Please tell me what I am doing wrong. I am using RStudio

Directions:

1. In R, create two data frames for students with the following fields and populate with 10 students

First dataframe, stu.info

studentid : num

status : chr (freshmen, sophomore, junior, senior)

gender : chr (F or M)

age : num

Second dataframe stu.eddetails

studentid: num

employment: chr (Y or N)

GPA : num

Major ; char

Perform the following:

a. display both the data frames

b. merge the two data frames

c. display the columns studentid, major and GPA

d. Display rows 6 to 10

My code:

student.id <- sprintf(ABC%d, 1:10)

Name <- c(Paola Mccready,Adaline Woolwine,Claude Carrara,Julietta Barrett,Delicia Halladay,Latarsha Coale,Phebe Corrales,Kerrie Chadwick,Augustine Fuerst,Zachariah Vautour)

Status <- c(Senior,Sophomore","Sophomore,Freshman,Junior,Senior,Sophomore","Sophomore,Freshman,Junior)

Gender <- c(F,F,F,M,F,F,F,F,M,M)

Age <- c(22,20,19,18,17,20,26,22,19,20)

stu.info<- data.frame(student.id,Name,Status,Gender,Age)

Employment <- c(Y,N,N,N,N,N,N,N,N,N)

GPA <- c(2.0,3.5,2.8,3.0,3.5,2.0,2.8,3.9,4.0,4.0)

Major <- c("Public Administration","Psychology","Medicine,Information Technology,Computer Science,Biology,Sociology,Law,Performing Arts,Mathematics,Civil Engineering)

stu.eddetails <- data.frame(student.id,Employment,GPA,Major)

print("Printing the Dataframes")

print(stu.info)

print(stu.eddetails)

stu<- merge(stu.info,stu.eddetails,by="student.id")

print(stu[c("Name", "Major","GPA")])

print(stu[c(0:9),])

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!