[R] Logical test and look up table

Wensui Liu liuwensui at gmail.com
Sun Jan 20 01:43:42 CET 2008


here is another one.

x <- read.table(textConnection("
id source Type
1  A23    M
2  A24    N
3   A9    Y
4  A32    E
5  A25    R
6  A14    V
7  A10    G
8  A12    W
9  A11    J
10 A13    Q
11   G    O"), header = TRUE, as.is = TRUE);

y <- read.table(textConnection("
id  Source
1     A10
2     A32
3     A10
4     A25
5     A32
6       G
7     A24
8     A32
9     A32
10    A23
11    A23
12    A32
13    A10
14    A14
15    A10
16    A25
17    A23
18    A25
19    A14
20    A32
21     A9
22    A12
23    A14
24    A14
25    A25
26    A23
27    A11
28    A25
29    A12
30    A24"), header = TRUE, as.is = TRUE);

library(sqldf);

wanted <- sqldf("select x.source, x.type from x inner join y on
x.source = y.source");


On Jan 19, 2008 8:57 PM, Nikola MARKOV <markov at lyon.inserm.fr> wrote:
> Dear R users,
> I have a data frame with one column (4000 rows) containing name codes
> (factor with 63 levels). I would like to  associate each name with a
> particular Type (coded as 1,2,3,4,H or H1) in a second column. Is it
> possible to do a lookup table of associations (i.e. A23 is of type 1, A13
> is of type 3 ...) so as to fill up automatically the $Type column.
>
> df()
> $Source    $Type
> A23
> A24
> A9
> A32
> A25
> A14
> A10
> A12
> A11
> A13
> G
>
>
> Alternative solutions are also welcome.
> Thanks in advance
>
> P.S. I found a discussion mentioning match() and %in% but it does not seem
> adapted.
>
> --
> Nikola Markov
> Inserm U 846 Stem cells and brain research institute
> 18 av Du Doyen Lepine
> 69500 Bron
> France
>
> ______________________________________________
> 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.
>



-- 
===============================
WenSui Liu
Statistical Project Manager
ChoicePoint Precision Marketing
(http://spaces.msn.com/statcompute/blog)



More information about the R-help mailing list