Hello!
I have a problem with R .... I have a file called dados_dia
with different meteorological variables: Índice de claridade (I.Cla),
Wind speed (speed), Umidade relativa (hH)
and Temperatura do ar (Tai)
. I need to find the dates on which a series of combinations of these variables occur (144 combinations, to be more exact). For this I have a script in which I use a " for
" to generate these combinations and to find the dates. Because each combination results in different date quantities, I can not write those dates in a vector or another file, just make a print
.
follows the script:
I.Cla <- c(0,0.3,0.6,0.9)
speed <- c(0,2,4,8)
Tair <- c(0,14,19,24,40)
rH <- c(0,70,80,90,100)
combinacao = NULL
m=1
for(i in 2:4){
for(j in 2:4){
for(l in 2:5){
for(k in 2:5){
######################################################################
############# condições das variáveis ################################
combinacao[m] <- paste('I.Cla > ',I.Cla[i-1],' e I.Cla <= ',I.Cla[i],
'speed > ', speed[j-1],' e speed <= ',speed[j],
'Tair > ',Tair[l-1],' e Tair <= ',Tair[l],
'rH > ',rH[k-1],' e rH <= ',rH[k] )
m=m+1
#####################################################################
############# datas em que ocorrem cada condição das variáveis ######
print(c(dados_dia$date[dados_dia$I.Cla > I.Cla[i-1] &
dados_dia$I.Cla <= I.Cla[i] &
dados_dia$speed > speed[j-1] &
dados_dia$speed <= speed[j] &
dados_dia$Tair > Tair[l-1] &
dados_dia$Tair <= Tair[l] &
dados_dia$rH > rH[k-1] &
dados_dia$rH <= rH[k]] ) )
}
}
}
}
I need the conditions of the variables (combination) to be the columns of my data.frame
and the dates generated in the print are arranged in the columns that match the same. Note: Results range from zero to 20 dates.