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
Maybe something like this is going to help you?
data.frame(c("Name one", "Name two")) -> my.data
colnames(my.data) <- "Names"
rbind(my.data, data.frame(Names="name three"))
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