[R] Assigning values based on a separate reference (lookup) table
daniel at umd.edu
Fri Aug 14 20:56:44 CEST 2009
This is just one suggestion for a solution, and I think there may be much
more elegant ones out there. However, this should work.
1. Reshape your data in long format
2. Merge the table that holds the values you want to multiply your data with
with your reshaped dataset (this may require transformation of the table
that holds the values that are to be multiplied).
3. Perform multiplication
4. Reshape the data in long format back in wide format.
Here is a stepwise example:
##Simulate random data
Then merge new.x with with the columns of the table you want to multiply
with (see ?merge). This may require extracting data/reshaping of the
multiplier table and/or transforming variables in new.x to make new.x
conformable with table that it is to be merged with.
##Reshape new.x2 back to the initial wide format of the matrix
cuncta stricte discussurus
Von: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] Im
Auftrag von Steve Murray
Gesendet: Friday, August 14, 2009 1:49 PM
An: r-help at r-project.org
Betreff: [R] Assigning values based on a separate reference (lookup) table
Dear R Users,
I have a data frame of 360 rows by 720 columns (259200 values). For each
value in this grid I am hoping to apply an equation to, to generate a new
grid. One of the parts of the equation (called 'p') relies on reading from a
separate reference table. This is Table 4 at:
hod (scroll down a little).
Therefore, 'p' relies on the latitude of the values in the initial 360 x 720
data frame. The row names of the data frame contain the latitude values and
these range from between 89.75 to -89.75 (the latter being South of the
My question is, how do I go about forming a loop to read each of the 259200
values and assign it a 'p' value (from the associated reference table),
based on it's latitude?
My thinking was to do a series of 'if' statements, but this soon got very,
very messy - any ideas which get the job done (and aren't a riddle to
follow), would be most welcome.
Many thanks for any advice,
[[elided Hotmail spam]]
R-help at r-project.org mailing list
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help