r - Error when converting dataframe row to character vector -
so i've got following dataframe, datafr.
x1 x2 x1.1 x2.1 composite element composite element 14-3-3_epsilon-m-c -0.8660101895 14-3-3_epsilon-m-c -0.6814387425 4e-bp1_ps65-r-v 0.1056560215 4e-bp1_ps65-r-v 0.1787506005 4e-bp1_pt37t46-r-v 0.6408257495 4e-bp1_pt37t46-r-v -0.7485933875 4e-bp1_pt70-r-c 0.6413568085 4e-bp1_pt70-r-c 0.9554481415
i want make second row column names, @ row
datafr[1,]
and should be
x1 x2 x1.1 x2.1 composite element composite element
however, when convert character vector words changing numbers...
as.character(c(datafr[1,])) [1] "49" "161" "49" "161"
what going on?
the problem data.frame columns not characters factors (read difference in r introduction.)
you have do:
as.character(unlist(datafr[1, ]))
to character vector out ot current data. however, might want fix problem upstream within code:
you try make sure data.frame not contain factors in first place. often, done adding stringsasfactors = false
functions data.frame
, as.data.frame
, read.table
, read.csv
might have used them. if used read.table
somewhere, highly suggest @ using header = true
colnames wanted in first place.
Comments
Post a Comment