Once we have generated a data and converted it into a data frame, we can edit any row or column of a data frame.
We can add or extract any column of a data frame using the dollar ($) symbol, as depicted in the following code:
data = data.frame(x = c(1:4), y = c("tom","jerry","luke","brian")) data$age = c(2,2,3,5) data
In the preceding example, we have added a new column called
age using the
$ operator. Alternatively, we can also add columns and rows using the
cbind() functions in R as follows:
age = c(2,2,3,5) data = cbind(data, age)
rbind functions can also be used to add columns or rows to an existing matrix.
To remove a column or a row from a matrix or data frame, we can simply use ...