inserting new row cause type conversion in R

16 Views Asked by At
    no <- c(10, 20, 30)
    age <- c(18, 21, 20)
    gender <- c('F', 'M', 'F')

    students <- data.frame(no, age, gender)

    # here type conversion occurs
    students['4', ] <- c(40, 20, 'F')
    str(students)

result is like $ age: chr "18" "21" ...

why data type changes and how I prevent it?

what I tried: googling for 10 minutes and got nothing

0

There are 0 best solutions below