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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
| # Working directory######
setwd("C:/Users/marie/Desktop/Stage_2017/mail_stage_wimereux/")
# Lecture fichiers
data_sat=read.table("data_sat3.csv", header=T, sep=";", dec=".", na.strings="0")
data_insitu=read.table("data_insitu3.csv", header=T, sep=";", dec=".")
raw_data_insitu=read.table("FB_CHROME_all_clean.csv", header=T,sep=";", dec=".")
# Creation d un fichier unique
m=cbind(data_insitu,data_sat)
# Indexation
ID= m$ID
jn=grep("JN",colnames(m))
j0=grep("J0",colnames(m))
jp=grep("JP",colnames(m))
xn=grep("XN",colnames(m))
x0=grep("X0",colnames(m))
xp=grep("XP",colnames(m))
yn=grep("YN",colnames(m))
y0=grep("Y0",colnames(m))
yp=grep("YP",colnames(m))
mneuron=grep("neurone_",colnames(m))
# Déclaration de variable
neurone_jour_i=numeric(length(ID))
neurone1 = m[,mneuron[mneuron %in% j0[j0 %in% x0[x0 %in% y0]]]]
neurone2 = as.matrix.data.frame(m[,mneuron[mneuron %in% j0]])
neurone3 = as.matrix.data.frame(m[,mneuron])
# 1ère méthode
for(i in 1:length(ID)){
if(!is.na(neurone1[i])){
neurone_jour_i[i]=neurone1[i]
}else if(!is.na(neurone2[i,]) && max(table(neurone2[i,]))>=3){
neurone_jour_i[i]=as.integer(names(which.max(table(neurone2[i,]))))
}else{
neurone_jour_i[i]=as.integer(names(which.max(table(neurone3[i,],useNA = "always"))))
}
}
# 2ème méthode
for(i in 1:length(ID)){
if(!is.na(neurone1[i])){
neurone_jour_i[i]=neurone1[i]
}else if(!is.na(neurone2[i,]) && max(table(neurone2[i,]))>=3){
neurone_jour_i[i]=as.integer(names(which.max(table(neurone2[i,]))))
}else{
if(!is.na(neurone3[i,])){
neurone_jour_i[i]=as.integer(names(which.max(table(which(!is.na(neurone3[i,]))))))
}
else{
neurone_jour_i[i]=0
}
}
} |
Partager