Complete the code to add a new column age with value 30 to the data frame df.
df$age <- [1]To add a new column with a fixed value, assign the value directly. Here, 30 is assigned to df$age.
Complete the code to remove the column age from the data frame df.
df <- df[ , [1] ]To remove a column, select columns where the name is not equal to "age". This keeps all columns except age.
Fix the error in the code to add a new column height with values from the vector c(160, 170, 180).
df$height <- [1]c().In R, vectors are created with c(). Using square brackets or parentheses alone is incorrect syntax.
Fill both blanks to add a new column weight with values from c(60, 70, 80) and then remove the column age.
df$[1] <- c(60, 70, 80) df <- df[ , [2] ]
First, assign the vector to the new column named weight. Then, remove the age column by selecting columns where the name is not "age".
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.
df$[1] <- toupper(df$name) df$score <- [2] df <- df[ , [3] ]
c() for the vector.Assign uppercase names to a new column name_upper. Then add score with the given vector. Finally, remove the height column by selecting columns not named "height".