This code is first reading data from 12 excel files. In each file, for different rows 1,3,5,7,9,11 (patients), the average of 60 values is taken for each row. Then, the maximum average from the 12 averages is taken and outputted along with the row it belongs to and in which file the max average was found.
files=list.files(path = "data",pattern = "inflammation", full.names = TRUE)
for (patient in seq(1,11,2)){
Maxavg<-0
MaxFile<-0
for (f in files){
dat<-read.csv(file = f, header=FALSE)
if (rowMeans(dat[patient,])>Maxavg) {
MaxFile<-f
Maxavg<-rowMeans(dat[patient,])
}
}
print(Maxavg)
print(MaxFile)
}
I get the following printout in the console:
1
6.8
[1] "data/inflammation-06.csv"
3
6.85
[1] "data/inflammation-03.csv"
5
6.95
[1] "data/inflammation-04.csv"
7
7.075
[1] "data/inflammation-04.csv"
9
6.7
[1] "data/inflammation-06.csv"
11
6.95
[1] "data/inflammation-11.csv"
My question is for how to graph the given data. If the maximum average > 13, create a box plot of the 60 daily values of the patient in the data value in which the maximum average was found. Otherwise, generate a simple plot of these daily values. Put the file name and patient number as the title of each plot.
if (Maxavg > 13) {
boxplot(dat[patient,], main = MaxFile)
} else {
plot(dat[patient,], main = MaxFile)
}
Does this need to be a part of the above for loop? How am I supposed to graph the 60 values for the specified patient (i.e. row) i.e. how do I call upon that row and all the columns to be graphed and subsequently set the title? It really isn't working for me.
Aucun commentaire:
Enregistrer un commentaire