Tsallaka zuwa abun ciki
Justice Tech School

Adding and Changing Columns

Assign to a new name to add a column. Use rbind and cbind to combine.

Example
df <- data.frame(a = 1:3)
df$b <- df$a * 2
df$c <- ifelse(df$a > 1, "big", "small")
print(df)
print(rbind(df, data.frame(a = 9, b = 18, c = "big")))
df$b <- NULL
print(names(df))

Exercise

Remove a column.

df$b <- 

Quiz Test

What does ifelse do?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.