r - How to display only corresponding computed result and not all results for each row when using [tapply] -
i'm having issues on displaying results. stored 3 vectors dataframe , perform computation , store new vector before combining new vector dataframe.
h=c(155,150,165,190,177) w=c(85,90,72,99,55) g=c("f","f","m","f","m") df=data.frame(h,w,g) row.names(df)=c("alpha","bravo","charlie","foxtrot","echo") bmi=tapply(df$w,df$h,function(calc){(df$w/(df$h)^2)*10000}) cbind(df,bmi)
and printed result
h w g bmi alpha 155 85 f 35.37981, 40.00000, 26.44628, 27.42382, 17.55562 bravo 150 90 f 35.37981, 40.00000, 26.44628, 27.42382, 17.55562 charlie 165 72 m 35.37981, 40.00000, 26.44628, 27.42382, 17.55562 foxtrot 190 99 f 35.37981, 40.00000, 26.44628, 27.42382, 17.55562 echo 177 55 m 35.37981, 40.00000, 26.44628, 27.42382, 17.55562
however, want display
h w g bmi alpha 155 85 f 35.37981 bravo 150 90 f 40.00000 charlie 165 72 m 26.44628 foxtrot 190 99 f 27.42382 echo 177 55 m 17.55562
Comments
Post a Comment