Perhaps this will help.

Jean


df <- structure(list(Left = c(9L, 4L, 2L, 6L, 3L, 4L, 3L, 4L, 10L, 9L),
 Right = c(8L, 3L, 1L, 5L, 1L, 1L, 2L, 2L, 8L, 10L)),
.Names = c("Left", "Right"), class = "data.frame", row.names = 1:10)

lookup <- structure(list(input = c(5L, 10L, 4L, 8L, 6L, 5L, 7L, 2L, 9L,
10L, 2L),
 output = c(1L, 1L, 2L, 3L, 5L, 6L, 6L, 7L, 7L, 7L, 8L)),
.Names = c("input", "output"), class = "data.frame", row.names = 1:10)

df2 <- merge(df, lookup, by.x="Left", by.y="input", all.x=TRUE)
names(df2)[names(df2)=="output"] <- "Leftout"

df3 <- merge(df2, lookup, by.x="Right", by.y="input", all.x=TRUE)
names(df3)[names(df3)=="output"] <- "Rightout"

   Right Left Leftout Rightout
1      1    2       7       NA
2      1    2       8       NA
3      1    3      NA       NA
4      1    4       2       NA
5      2    3      NA        7
6      2    3      NA        8
7      2    4       2        7
8      2    4       2        8
9      3    4       2       NA
10     5    6       5        6
11     5    6       5        1
12     8    9       7        3
13     8   10       1        3
14     8   10       7        3
15    10    9       7        1
16    10    9       7        7



On Thu, Jul 25, 2013 at 10:13 AM, Juan Antonio Balbuena
<j.a.balbu...@uv.es>wrote:

>
>    Hello
>    I hope that there is a simple solution to this apparently complex
> problem.
>    Any help will be much appreciated:
>    I have a dataframe with Left and Right readings (that is, elements in
> each
>    row are paired). For instance,
>        Left Right
>     [1]  9    8
>     [2]  4    3
>     [3]  2    1
>     [4]  6    5
>     [5]  3    1
>     [6]  4    1
>     [7]  3    2
>     [8]  4    2
>     [9]  10   8
>    [10]  9   10
>    I  need  to  produce a new data frame where the values are transformed
>    according to a look-up table such as
>            input    output
>     [1]     5      1
>     [2]    10     1
>     [3]     4      2
>     [4]     8      3
>     [5]     6      5
>     [6]     5      6
>     [7]     7      6
>     [8]     2      7
>     [9]     9      7
>    [10]    10    7
>    [11]     2     8
>    So  [1, ] in the new dataframe would be 7 3. Quite simple so far, but
> what
>    makes things complicated is the multiple outputs for a single input. In
> this
>    example, 10 corresponds to 1 and 7 so [9, ] in the input dataframe must
>    yield two rows in its output counterpart: 1 3 and 7 3. Likewise the
> output
>    for  [10, ] should be 7 1 and 7 7. In addition, given that 3 and 1 are
>    missing as inputs the output for [5, ] should be NA NA.
>    Thank you very much for your time.
>    Juan Antonio Balbuena
>
>    --
>
>    Dr. Juan A. Balbuena
>    Marine Zoology Unit
>    Cavanilles Institute of Biodiversity and Evolutionary Biology
>    University of
>    Valencia
>    [1]http://www.uv.es/~balbuena
>    P.O. Box 22085
>    [2]http://www.uv.es/cavanilles/zoomarin/index.htm
>    46071 Valencia, Spain
>    [3]http://cetus.uv.es/mullpardb/index.html
>    e-mail: [4]j.a.balbu...@uv.es    tel. +34 963 543 658    fax +34 963
> 543 733
>    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>    NOTE! For shipments by EXPRESS COURIER use the following street address:
>    C/ Catedrático José Beltrán 2, 46980 Paterna (Valencia), Spain.
>    ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>
> References
>
>    1. http://www.uv.es/%7Ebalbuena
>    2. http://www.uv.es/cavanilles/zoomarin/index.htm
>    3. http://cetus.uv.es/mullpardb/index.html
>    4. mailto:j.a.balbu...@uv.es
> ______________________________________________
> 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.
>

        [[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