Last answered:

29 Apr 2020

Posted on:

29 Apr 2020

0

Rbind does not work

Hi, we had the following exercise and it worked well till last rbind. I have the following warning. Can you help to figure it out? Thank you. Error in match.names(clabs, names(xi)) :
names do not match previous names   name <- c("Flipper", "Bromley", "Nox", "Orion", "Dagger", "Zizi", "Carrie")
mo <- c(53, 19, 34, 41, 84, 140, 109)
size <- c("medium", "small", "medium", "large", "small", "extra small", "large")
weight <- c(21, 8, 4, 6, 7, 2, 36)
breed <- c("dog", "dog", "cat", "cat", "dog", "cat", "dog") pets <- data.frame(mo, size, weight, breed)
names(pets) <- c("Months old", "Size", "Weight", "Breed")
rownames(pets) <- name
pets vaccinated <- c("Yes", "Yes", "No", "Yes", "No", "No", "Yes")
petsv <- cbind(pets, "Vaccinated" = vaccinated)
petsv milo <- data.frame(row.names = "Milo", Months.old = 67, Size = "small", Weight = 7, Breed = "dog", Vaccinated = "Yes")
petsvm <- rbind(petsv, milo)
petsvm
2 answers ( 0 marked as helpful)
Posted on:

29 Apr 2020

0
As the error message indicated, the column name that you want to rbind (Months.old) is different from the main column name (Months old). 
Posted on:

29 Apr 2020

0
Hi Joonseok, when defining name, the space is allowed like "Months old"  names(pets) <- c(“Months old”, “Size”, “Weight”, “Breed”).   when define a row with name, the space is not allowed, like Months old milo <- data.frame(row.names = “Milo”, Months old = 67, Size = “small”, Weight = 7, Breed = “dog”, Vaccinated = “Yes”). so How can we keep the name with space if I want to add a row as in this example? 

Submit an answer