0
0
R Programmingprogramming~10 mins

Adding and removing columns in R Programming - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to add a new column age with value 30 to the data frame df.

R Programming
df$age <- [1]
Drag options to blanks, or click blank then click option'
A30
B"age"
Cage
Dc(30)
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around 30 makes it a string, not a number.
Assigning the column name instead of the value.
2fill in blank
medium

Complete the code to remove the column age from the data frame df.

R Programming
df <- df[ , [1] ]
Drag options to blanks, or click blank then click option'
Anames(df) == "age"
B!(names(df) == "age")
C"age"
Dnames(df) != "age"
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of != selects only the column to remove.
Using quotes alone does not filter columns.
3fill in blank
hard

Fix the error in the code to add a new column height with values from the vector c(160, 170, 180).

R Programming
df$height <- [1]
Drag options to blanks, or click blank then click option'
Ac(160, 170, 180)
B[160, 170, 180]
C(160, 170, 180)
Dlist(160, 170, 180)
Attempts:
3 left
💡 Hint
Common Mistakes
Using square brackets which are not vector constructors in R.
Using parentheses without c().
4fill in blank
hard

Fill both blanks to add a new column weight with values from c(60, 70, 80) and then remove the column age.

R Programming
df$[1] <- c(60, 70, 80)
df <- df[ , [2] ]
Drag options to blanks, or click blank then click option'
Aweight
Bnames(df) != "age"
Cnames(df) == "age"
Dage
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong column name in the first blank.
Using == instead of != in the second blank.
5fill in blank
hard

Fill all three blanks to create a new column with uppercase names from df$name, add a column score with values c(90, 85, 88), and remove the column height.

R Programming
df$[1] <- toupper(df$name)
df$score <- [2]
df <- df[ , [3] ]
Drag options to blanks, or click blank then click option'
Aname_upper
Bc(90, 85, 88)
Cnames(df) != "height"
Dheight
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong new column name.
Not using c() for the vector.
Using == instead of != to remove the column.