R: losing column names when adding rows to an empty data frame

前端 未结 8 1166
旧时难觅i
旧时难觅i 2020-12-05 01:36

I am just starting with R and encountered a strange behaviour: when inserting the first row in an empty data frame, the original column names get lost.

example:

8条回答
  •  醉话见心
    2020-12-05 02:13

    You can do this:

    give one row to the initial data frame

     df=data.frame(matrix(nrow=1,ncol=length(newrow))
    

    add your new row and take out the NAS

    newdf=na.omit(rbind(newrow,df))
    

    but watch out that your newrow does not have NAs or it will be erased too.

    Cheers Agus

提交回复
热议问题