Replace a row in a R data.frame -
i'm looking easy way replace row in data.frame
dados <- data.frame(a = c("a", "b", "c"), b = c(1,2,3)) new_record <- data.frame(a = "g", b = 99) # replace row dados[2, ] <- new_record[1, ] this doesn't work. what's easiest way make work?
if want / have keep column a factor, can adjust factor levels first , create new data set:
levels(dados$a) <- union(levels(dados$a), new_record$a) dados[2, ] <- new_record[1, ] dados # b #1 1 #2 g 99 #3 c 3
Comments
Post a Comment