-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathCHAMP data reshaping code
44 lines (34 loc) · 2.02 KB
/
CHAMP data reshaping code
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
setwd("c:/Users/mqbpjhr4/Documents")
champtable<-read.table("CMFTfile.csv", header=T,sep=",")
head(champtable)
#CHECK FOR WEIGHT AND HEIGHT DATA ENTRY ERRORS.
#USES THE NHS 'VALIDATION OF CHILD MEASUREMENT PROGRAMME DATA' REPORT 2016 ERROR REJECTION CUTOFFS
#Update this with a table?
attach(champtable)
library(lubridate)
ndate1<-paste(DateOfBirth,"-01",sep=""); ndate1 #The data does not have day values within the dates, so these are assigned as the 1st of the month for R purposes.
ndate1<-(as.Date(ndate1))
ndate2<-paste(AssessmentDate,"-01",sep=""); ndate2
ndate2<-(as.Date(ndate2))
require(lubridate)
champtable$ageattest<-floor(difftime(strptime(ndate2, format="%Y-%m-%d"),
strptime(ndate1, format="%Y-%m-%d"),units="weeks"))
champtable$ageattest<-as.numeric(champtable$ageattest)
attach(champtable)
#Gives ages in weeks
#REMOVE OUT OF RANGE AGES DUE TO DATE ENTRY ERRORS
champ<-champtable
champ$ageattest<-as.numeric(champ$ageattest)
champ<-subset(champ, champ$ageattest<=625 & champ$ageattest>=208)
attach(champ)
champ$ageattest<-as.integer(champ$ageattest)
champ <- champ[order(champ$ChildID),]
#DEFINE FACTORS
sch<-as.character(SchoolCode)
ID<-as.character(ChildID)
champ$BMI<-champ$WeightKG/(champ$HeightCM/100)^2
LMStable<-file(paste("LMStableedited.csv"), open="w")
cat("ChildID","SchoolCode","AcademicYear","AssessmentDate","DateOfBirth","Gender","HeightCM","WeightKG","BMI","IsAccountRegistered","Ethnicity","PostcodeDecile","ageattest","\n", sep=",",file="LMStable1005.csv",append=TRUE)
for (n in 1:108364){cat((paste(champ$ChildID[n])),(paste(champ$SchoolCode[n])),(paste(champ$AcademicYear[n])),(paste(champ$AssessmentDate[n])),(paste(champ$DateOfBirth[n])),(paste(champ$Gender[n])), (paste(champ$HeightCM[n])),(paste(champ$WeightKG[n])),(paste(champ$BMI[n])),(paste(champ$IsAccountRegistered[n])),(paste(champ$Ethnicity[n])),(paste(champ$IMDdecile[n])),(paste(champ$ageattest[n])),"\n", file="LMStable1005.csv", sep=",", fill=FALSE, labels=NULL, append=TRUE)
}
#USE the excel plugin LMSGrowth to add SDs from BMIs and save table.