Sorry for not being more clear.

I'll try to explain again.

I have a rather large DEM and I need to scale daily temperature values for
10 years.

I am using the sapply function to adjust temperatures (t.mean.1.c) based on
lapse rates across DEM points (cdem) which meet the condition of elevation
being greater than 300m. Below ~300m the lapse rate calculate changes
because temperatures decrease with elevation. Above ~300m the lapse rates
calculation must account for an inversion, where temperature increases with
elevation.

What I would like as a result is the values of the DEM which are lower than
300m to retain a generic lapse rate adjustment, and the DEM values great
than 300 to be treating using a different function.


t.mean.1.c <- c(-15, -20, -30, -20, -25, -35, -40, -8, 9, 10)
cdem <- c(300, 400, 700, 900, 1000, 250, 200, 300, 500, 650, 650, 1200,
1400, 3200, 2000)
cdem.mat <- sapply(cdem[which(cdem >= 900)], function(x) get("t.mean.1.c")
- (x * -0.0065)) #this just gives me a
#result of only the six values

I'm going to make this even more simple to show what I want as output.

t.mean.1.c <- c(-14, -20)
cdem <- c(300, 400, 700, 900)
cdem.mat.1 <- sapply(cdem[which(cdem >= 900)], function(x)
get("t.mean.1.c") - (x * -0.0065))
cdem.mat.2 <- sapply(cdem[which(cdem < 900)], function(x) get("t.mean.1.c")
+ (x * -0.0065))

cdem.mat.1 #right now I get this, which is only the two temperature scaled
to the 900 m elevation case
#       [,1]
#[1,]  -8.15
#[2,] -14.15

#What I want:

#       [,1]        [,2]   [,3]         [,4]
#[1,] -15.95  -16.6    -18.55     -8.15
#[2,] -21.95   -22.6   -24.55     -14.15

Maybe I can combine in the sapply function an if else statement? I haven't
tested the below try.

sapply( if (cdem < 900)] function(x) get("t.mean.1.c") - (x * -0.0065)
else function(x) get("t.mean.1.c") + (x * -0.0065) )

Finally, I want to output everything into one single matrix array.

I hope that is more clear.

Thanks for your assistance.

Katrina






On Sun, Nov 27, 2011 at 7:35 PM, David Winsemius <dwinsem...@comcast.net>wrote:

>
> On Nov 27, 2011, at 10:15 PM, Katrina Bennett wrote:
>
>  Hi all,
>>
>> I'm working to apply a function that will generate a matrix of results
>> only
>> when a specific criteria is met.
>>
>> I want my final results to be a matrix with both the values that meet the
>> criteria (the results of the function), and those that to do in the same
>> positions in the matrix (the original numbers).
>>
>> Here's a sample of what I would like to do:
>>
>> t.mean.1.c <- c(-15, -20, -30, -20, -25, -35, -40, -8, 9, 10)
>> cdem <- c(300, 400, 700, 900, 1000, 250, 200, 300, 500, 650, 650, 1200,
>> 1400, 3200, 2000)
>> cdem.mat <- matrix(NA, 10, 15)
>> cdem.mat <- cdem.mat(sapply(cdem[which(**cdem >= 900)], function(x)
>>
> ......................^
> cdem.mat is not a function, cannot use "(".
>
>
>
>  get("t.mean.1.c") - (x * -0.0065)))
>>
>> I want cdem.mat to be the same size as the the first call of it, with NA
>> values where the cdem is < 899.
>>
>
> You are only offering 10 values as replacements and an unequal number of
> condition regardless of whether you count the qualifying cdem conditions
> (6) or the total conditions(15). So you will need to be more clear about
> how you want the conditions to apply to values. They stepping the audience
> through the first few decisions and say where you want the values placed.
> Maybe you should also say whether you expect values to be recycled (the
> default with matrix assignment).
>
> I suppose it is possible that you want the results of this:
>
> cdem.mat[cdem>899] <-  t.mean.1.c - (cdem * -0.0065)
>
> .... but I'm guessing not.
>
>  I thought this would fill it in but it
>> seems to just over write it and I only end up with the rows where cdem is
>> greater than 900.
>>
>> Thank you,
>>
>> Katrina
>>
>>
>>
>> --
>> Katrina E. Bennett
>> PhD Student
>> University of Alaska Fairbanks
>> International Arctic Research Center
>> 930 Koyukuk Drive, PO Box 757340
>> Fairbanks, Alaska 99775-7340
>> 907-474-1939 office
>> 907-385-7657 cell
>> kebenn...@alaska.edu
>>
>>
>> Personal Address:
>> UAF, PO Box 752525
>> Fairbanks, Alaska 99775-2525
>> bennett.katr...@gmail.com
>>
>>        [[alternative HTML version deleted]]
>>
>> ______________________________**________________
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help>
>> PLEASE do read the posting guide http://www.R-project.org/**
>> posting-guide.html <http://www.R-project.org/posting-guide.html>
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> David Winsemius, MD
> West Hartford, CT
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to