String as factor in R

前端 未结 2 2019
离开以前
离开以前 2021-01-12 17:02

When creating a data frame in R, strings are by default converted to factors (which I don\'t mind). But when I want to create a new row to my data frame, I can\'t find a way

2条回答
  •  耶瑟儿~
    2021-01-12 17:36

    The trick is to only rbind a data.frame with another data.frame and not, as you have done, with a simple vector:

    my.data <- data.frame(Names = c("Name one", "Name two"))
    new.row1 <- data.frame(Names = c("Name three"))
    rbind(my.data, new.row1)
    
    ##        Names
    ## 1   Name one
    ## 2   Name two
    ## 3 Name three
    

提交回复
热议问题