r - How to move cells with a value row-wise to the left in a dataframe -
i'm working on dataframe looks one.
x1 x2 x3 x4 x1 b na c x2 d na na e x3 f g h x4 j na k l
what want move each cell has value row-wise left. @ end cells have value should gathered left while cells nas should gathered right.
finally, dataframe should this:
x1 x2 x3 x4 x1 b c na x2 d e na na x3 f g h x4 j k l na
unfortunately, have no thought how it.
thank much help. (maybe explain code doing?)
rami
yourdata[]<-t(apply(yourdata,1,function(x){ c(x[!is.na(x)],x[is.na(x)])}))
should work : each row, replaces row vector consists of, first, value not na, na values.
r data.frame
No comments:
Post a Comment