R syntax: analysing weight records (Libra) 11 Novembre 11+01:00 2019
Posted by xarxes in Codi R, estadística.add a comment
Estic fent seguiment del pes periòdicament, i uso Libra com a aplicació (Android). Exportant les dades a .csv es pot analitzar amb R. Esta és al sintaxi, si la vols aprofitar.
I am recording the weight periodically, using Libra application (Android). Exporting the data to a .csv file is possible to analyse with R. This is the syntax, if you want to take.
libra <- read.csv("/home/Libra_2019-11-01 v2.csv", sep = ";", header = TRUE, dec='.') mean(libra$weight) plot(libra$date, libra$weight, type="h", col="green") library(lubridate) libra$any <- year(ymd_hms(libra$date)) libra$mes <- month(ymd_hms(libra$date)) libra$dia <- day(ymd_hms(libra$date)) summary(libra) anual <- aggregate(libra$weight, by=list(libra$any), FUN=mean, na.rm=TRUE) mensual <- aggregate(libra$weight, by=list(libra$mes), FUN=mean, na.rm=TRUE) am <- aggregate(libra$weight, by=list(libra$any, libra$mes), FUN=mean, na.rm=TRUE) am library(lubridate) am$am <- ymd(paste(am$Group.1, am$Group.2, "15", sep="-")) plot(anual$Group.1, anual$x, type="b", col="black") plot(mensual$Group.1, mensual$x, type="b", col="black") library(ggplot2) library(scales) ggplot(am,aes(x=am,y=x))+geom_line() am <- mutate(am, x - lag (x)) am$xd <- am$"x - lag(x)" am$"x - lag(x)" <- NULL head(am) ggplot(am,aes(x=am,y=xd))+geom_point() + geom_smooth(method="loess", formula = y ~ poly(x, 2), fullrange=TRUE, level=.10) + ylim(-4, 4) #TAULA amt <- xtabs(x~Group.1+Group.2, am) amt