R: Insert a vector as a row in data.frame

前端 未结 3 1061
孤独总比滥情好
孤独总比滥情好 2020-12-14 01:04

Can I insert a vector as a row in a data.frame? If so how?

3条回答
  •  孤城傲影
    2020-12-14 01:44

    rbind is good, but really tricky though as to handle the exact row number before and after. A more rapid way is to use insertRow in the package miscTools.

    In the dataset example above, the code would be :

    my.df <- as.matrix(data.frame(a = runif(10), b = runif(10), c = runif(10)))
    my.vec <- c(1, 1, 1)
    new.df <- insertRow(my.df,7,my.vec)
    new.df
    

    Hope would be helpful.

提交回复
热议问题