a) I agreed with your suggestion about the condition "else". L = Level of
noise fluctuates during the various moments of the day (i.e L= L+5 between
18:00:00 and 21:59:59; L=L+10 between 22:00:00 and 05:59:59 and L = L
else).
b)
mytab is a data table including Time column, Level column, .... ,
Time <- Table[,"time"] and Level <- Table[, "Levele"]
c) Time format is "16/09/2006 03:38:37"
d)
the time interval [ 18:00:00 ; 21:59:59 ]and [ 22:00:00 ; 05:59:59] is
very important for me.
Best regards
Lassana KOITA
Chargé d'Etudes de Sécurité Aéroportuaire et d'Analyse Statistique /
Project Engineer Airport Safety Studies & Statistical analysis
Service Technique de l'Aviation Civile (STAC) / Civil Aviation Technical
Department
Direction Générale de l'Aviation Civile (DGAC) / French Civil Aviation
Headquarters
Tel: 01 49 56 80 60
Fax: 01 49 56 82 14
E-mail: Lassana.Koita@aviation-civile.gouv.fr
http://www.stac.aviation-civile.gouv.fr/
Uwe Ligges
Envoyé par : r-help-bounces@stat.math.ethz.ch
13/08/2007 10:39
A
KOITA Lassana - STAC/ACE
cc
r-help@stat.math.ethz.ch
Objet
Re: [R] need help to manipulate function and time interval
KOITA Lassana - STAC/ACE wrote:
> Hi,
> data are extracted from MS Access with the format: ("%d/%m%Y %H%M%S");
ex:
> 16/09/2006 03:38:37
1. the example you gave in your first message is still not reproducible,
you gave the following:
myfunc <- function(mytab, Time, Level)
{
vect <- rep(0, length(mytab))
for(i in 1:length(vect))
{
for(j in 1:length(Time))
if(time[j] is between 18:00:00 and 23:59:59)
L[i] <- L[j]+5
vect[i] <- 10^((L[i])/10
if (time[j] is between 22:00:00 and 05:59:59)
L[i] <- L[j]+10
vect[i] <- 10^((L[i])/10
else
L[i] = L[j]
vect[i] <- 10^((L[i])/10
}
}
a) Please check the parentheses (some closing ")" are missing, you also
probably want to group some code "{}" that is executed in some of the
"if" conditions rather than executing the (syntactically erroneous) line
vect[i] <- 10^((L[i])/10
three times for each inner loop. Particularly, the "else" is
syntactically incorrect with not preceding "if".
So my guess is you want something like
myfunc <- function(mytab, Time, Level)
{
vect <- rep(0, length(mytab))
for(i in 1:length(vect))
{
for(j in 1:length(Time))
{
if(time[j] is between 18:00:00 and 23:59:59){
L[i] <- L[j]+5
vect[i] <- 10^(L[i]/10)
}
if (time[j] is between 22:00:00 and 05:59:59){
L[i] <- L[j]+10
vect[i] <- 10^(L[i]/10)
} else {
L[i] <- L[j]
vect[i] <- 10^(L[i]/10)
}
}
}
But I am really not sure about that and why you subsitute L[i] so many
times...!
b) What are mytab, Time and Level?
2. Which is the format do you have?
("%d/%m%Y %H%M%S")
*or*
16/09/2006 03:38:37
If the latter, you can use
dat <- strptime("16/09/2006 03:38:37", "%d/%m/%Y %H:%M:%S")
in order to get some POSIXlt object for later calculations.
3. What do you mean with
time[j] is between 22:00:00 and 05:59:59
Is the day of the date important or not for this comparison?
Uwe Ligges
> I still have error messneger
>
> Thank you for your help.
>
> Lassana KOITA
> Chargé d'Etudes de Sécurité Aéroportuaire et d'Analyse Statistique /
> Project Engineer Airport Safety Studies & Statistical analysis
> Service Technique de l'Aviation Civile (STAC) / Civil Aviation Technical
> Department
> Direction Générale de l'Aviation Civile (DGAC) / French Civil Aviation
> Headquarters
> Tel: 01 49 56 80 60
> Fax: 01 49 56 82 14
> E-mail: Lassana.Koita@aviation-civile.gouv.fr
> http://www.stac.aviation-civile.gouv.fr/
>
>
>
> Uwe Ligges
> 12/08/2007 15:24
>
> A
> Matthew Walker
> cc
> Henrique Dallazuanna , r-help@stat.math.ethz.ch, KOITA
> Lassana - STAC/ACE
> Objet
> Re: [R] need help to manipulate function and time interval
>
>
>
>
>
>
>
>
> Matthew Walker wrote:
>> Uwe Ligges wrote:
>>> Henrique Dallazuanna wrote:
>>>
>>>> Hi,
>>>>
>>>> Try whit:
>>>>
>>>> if(time[j] >= "18:00:00" & < "23:59:59")
>>>>
>>> This code is obviously wrong and does not help for the next few lines
>>> in the questioner's message, please do not post unsensible stuff.
>>>
>>> Uwe Ligges
>>>
>>>
>> Actually, I would have said that was quite an interesting solution. If
>> the time is guaranteed to be in this 8 character format, then that
>> idea's quite easily implemented:
>>
>> # Returns true if time is between 18:00:00 and 23:59:59
>> check_time <- function(time_string) {
>> if (nchar(time_string)!=8) stop ("Incorrect format")
>> time_string >= "18:00:00" & time_string <= "23:59:59"
>> }
>>
>>
>> > check_time("19:59:00")
>> [1] TRUE
>> > check_time("16:59:00")
>> [1] FALSE
>> >
>> > check_time("18:00:00")
>> [1] TRUE
>> > check_time("23:59:59")
>> [1] TRUE
>> > check_time("24:00:00")
>> [1] FALSE
>> >
>> > check_time("18:05")
>> Error in check_time("18:05") : Incorrect format
>>
>>
>> Perhaps there is an issue if the locale does not sort character-based
>> numbers in the same way as ASCII? But Otherwise, I can't see why this
>> solution wouldn't do the job.
> >
>> A more robust solution solution would parse the strings (?strptime) and
>> then check their days/hours/mins/seconds (?DateTimeClasses). But
>> perhaps the above is sufficient?
>
> Well, the interesting part of the original question that everynody seems
> to omit now was the second part:
>
> if (time[j] is between 22:00:00 and 05:59:59)
>
> hence the answer is still not sufficient (even if the syntax error has
> been corrected) - and hence I asked for the format the time is
> originally in.
>
> Uwe Ligges
>
>
>
>
>> Cheers,
>>
>> Matthew
>
>
> [[alternative HTML version deleted]]
>
>
>
> ------------------------------------------------------------------------
>
> ______________________________________________
> R-help@stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]