math - replace NA with data from another column in R -
i know how make na
's blanks following code:
imileft imiright imiavg na na na na 71.15127 na 72.18310 72.86607 72.52458 70.61460 68.00766 69.31113 69.39032 69.91261 69.65146 72.58609 72.75168 72.66888 70.85714 na na na 69.88203 na 74.47109 73.07963 73.77536 70.44855 71.28647 70.86751 na 72.33503 na 69.82818 70.45144 70.13981 68.66929 69.79866 69.23397 72.46879 71.50685 71.98782 71.11888 71.98336 71.55112 na 67.86667 na imileft <- ((aslcomptest$lhml + aslcomptest$lrml)/(aslcomptest$lfml + aslcomptest$ltml)*100) imileft <- sapply(imileft, as.character) imileft[is.na(imileft)] <- ""
but when code, won't allow me average of "imileft" , "imiright" or make "imiavg" same other column has numerical value.
imiavg<-((imileft + imiright)/2)
error in imileft + imiright : non-numeric argument binary operator
it same error if make as.numeric
try following. leave na
s are
rowsums(m, na.rm=true) / 2 - (is.na(l) + is.na(r)) ## m = cbind(imileft, imiright) l = imileft r = imiright
if have rows both columns na, have denominator
pmin(1, 2 - (is.na(l) + is.na(r)))
Comments
Post a Comment