[R] Min , Max

David Winsemius dwinsemius at comcast.net
Sat Apr 28 16:04:04 CEST 2012


On Apr 28, 2012, at 9:54 AM, Jonsson wrote:

> This code bellow will calculate average daily wind  
> speed(measurements are
> taken every three hours).
>
snipped overly complex code not needed to address the semantic error  
below.

> the values are measured in kelvin so i want to convert them to
> degree,therefor I want to subtract all values by 273.15 before  
> talking the
> average or max.... but did not work.In other words, i want this:  
> every value
> is subtracted by 273.15 first ,then do other calculations(Min, Max)Can
> anyone tell me what is wrong.Thanks
>
> tm[ta[i],tb[i]]= round(10 * mean(D[((d-1)*8 + 1:8)-273.15), i])) #  
> wrong

You should not be subtracting the temperature offset within the index  
if your goal was to subtract the same number from each value in a  
matrix. Move it outside the index/extract function. You didn't get an  
error from "[" because it automatically truncated the floating point  
numbers you were passingwhich should have been integer vectors.

  tm[ta[i],tb[i]]= round(10 * mean(D[((d-1)*8 + 1:8)-273.15),  
i]-273.15))

(No effort made to check for the sensibility of the assignment to the  
'tm' matrix.)

Note:
  c(1,2)[2.5]
#[1] 2  No error .... or even a warning.


>
> --
> View this message in context: http://r.789695.n4.nabble.com/Min-Max-tp4593065p4594774.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org 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.

David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list