Home > Blockchain >  Last Disappearing Columns (R)
Last Disappearing Columns (R)

Time:05-26

I'm trying to execute a guilty code:

cats <- data.frame(coat = c("calico", "black", "tabby"),
                   weight = c(2.1, 5.0, 3.2),
                   likes_string = c(1, 0, 1))
write.csv(x = cats, file = "data/feline-data.csv", row.names = FALSE)
cats <- read.csv(file = "data/feline-data.csv", stringsAsFactors = TRUE)
age <- c(2, 3, 5)
cbind(cats, age)

But, when I insert a level in my coat object and run the code the last column (age) disappears:

levels(cats$coat) <- c(levels(cats$coat), "tortoiseshell")
cats <- rbind(cats, list("tortoiseshell", 3.3, TRUE, 9))
cats

Someone could me explain why the last column disappears when I insert a level on my coat object?

CodePudding user response:

The reason is that the age was not assigned to 'cats' dataset

cats <- cbind(cats, age)
  • Related