Give examples of “rbind()” and “cbind()” functions in r
Answer Posted / Dharmendra Kumar Kannaujiya
In R, the `rbind()` function is used to bind or combine row-wise data from multiple vectors, matrices, or data frames. Here's an example of combining two data frames using `rbind()`:nn```Rn df1 <- data.frame(a = c(1, 2, 3), b = c('A', 'B', 'C'))n df2 <- data.frame(a = c(4, 5, 6), b = c('D', 'E', 'F'))n result <- rbind(df1, df2)n```nThe `cbind()` function in R binds or combines columns-wise data. Here's an example of combining two matrices using `cbind()`:nn```Rn mat1 <- matrix(c(1, 2, 3, 4), nrow = 2)n mat2 <- matrix(c(5, 6, 7, 8), nrow = 2)n result <- cbind(mat1, mat2)n```
| Is This Answer Correct ? | 0 Yes | 0 No |
Post New Answer View All Answers