Is there a way to write the following statement more efficiently? acceleration is a data frame.
accel[[2]]<- accel[[2]]-weighted.mean(accel[[2]]) accel[[3]]<- accel[[3]]-weighted.mean(accel[[3]]) accel[[4]]<- accel[[4]]-weighted.mean(accel[[4]])
Alternative
accel[2:4] <- lapply(accel[2:4], function(x) x-weighted.mean(x))
This is one way to do this.
accel[,2:4] = t(t(accel[,2:4]) - apply(accel[,2:4], 2, weighted.mean))
The following Marek spot has been fixed - thanks.
Moral: Always check your R-code before publishing!
Source: https://habr.com/ru/post/1751283/More articles:Javascript associative variable - javascriptMake two fields with the same height - htmlHow to set Windows UAC Shield overlay on a button using wxPython? - pythonhttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1751281/javascript-passing-changing-parameters-to-a-callback&usg=ALkJrhjpCCdE3wb7ZrhUvGAqbTM10zMM-AAndroid: How to implement WYSIWYG editor for custom content? - androidHow to perform a general insert in an entity infrastructure? - genericshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1751285/how-to-best-utilize-the-new-type-equivalance-features-to-host-the-mappoint-control-in-a-wpf-application&usg=ALkJrhgD5RbUOSnysR1zjZwLHLRRdvpfwwmysql: group by ID, get the highest priority for each identifier - mysqlJQuery drag & drop problem - javascripthttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1751288/forcing-tags-to-close-in-dynamic-text&usg=ALkJrhgMC4CQr7Eq8whT6MpKJRgUehex1wAll Articles