Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Use the following R code for questions at bottom gpa <- c(3.1, 3.2, 3.3, 3.4, 3.

ID: 3745068 • Letter: U

Question

Use the following R code for questions at bottom

gpa <- c(3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 4.7)

age <- c(21, 22, 23, 24, 25, 26, 27)

wt <- c(151, 142, 133, 164, 165, 166, 167)

df <- data.frame(gpa, age, wt)


1. Write the R code that outputs the element at the second row and third column of df.

2. Write the R code that outputs the second row of the data frame.

3. Write the R code that outputs the first column of the data frame.

4. Write the R code that removes the last row from df (and stores the new data frame in a variable called df1).

5.Write the R code that removes the last 2 columns from df (and stores the new data frame in a variable called df1).

6. Write the R code to calculate the wt divided by the age (for all observations), store this in a new column within df (named ‘weightPerAge’).

Explanation / Answer

gpa<-c(3.1,3.2,3.3,3.4,3.5,3.6,4.7)
age<-c(21,22,23,24,25,26,27)
wt<-c(151,142,133,164,165,166,167)
df<-data.frame(gpa,age,wt)
df


#1.To output the element at the second row and third column of df
df[2,3]
#2.To output the second row of the data frame
df[2,]
#3.To output first column of the data frame
df[,1]
#4.To remove last row from df(and stores the new data frame in a variable called df1)
df1 <- df[-nrow(df),]
df1
#5.To remove last 2 rows from df(and stores the new data frame in a variable called df1)
df1<-head(df,-2)
df1
#6.To calculate the wt divided by the age(for all observations), store this in a new column within df(named 'weightPerAge')
df <- within(df, weightPerAge <- wt / age )
df

Output:-

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote