Rbind and colnames


Below is the correct code, but the first time I coded like that: university_matrix <- rbind(“harvard”, “stanford”, “MIT”, “cambridge”, “oxford”, “columbia”), why when using this code for colnames it doesn’t work?

harvard <- c(1,1,1,1,3)
stanford <- c(2,9,3,4,10)
MIT <- c(3,3,2,2,1)
cambridge <- c(4,2,6,13,48)
oxford <- c(5,7,12,9,15)
columbia <- c(6,13,13,12,4)

Type your code below

category_names <- c(“world_rank”, “quality_of_education”, “influence”, “broad_impact”, “patents”)
university_matrix <- rbind(harvard, stanford, MIT, cambridge, oxford, columbia)
colnames(university_matrix) <- category_names

1 Like

Hello @hongchi0502 I don’t understand what you are trying to ask.

Here you are passing strings to rbind this will for a matrix of characters

> university_matrix
[1,] "harvard"
[2,] "stanford"
[3,] "MIT"
[4,] "cambridge"
[5,] "oxford"
[6,] "columbia"
1 Like

Please follow these guidelines

GUIDELINE #1: Format all code using Markdown - no screenshots
GUIDELINE #5: Include a link to mission URL if available
See these title in the post