Hi Jeremy,

Try

> frame1 <- structure(list(ID = structure(c(1L, 1L, 2L, 2L), .Label =
c("Guy1",
"Guy2"), class = "factor"), score = c(10L, 13L, 9L, 11L), test = c(1L,
2L, 1L, 2L), age = c(20L, 20L, 33L, 33L)), .Names = c("ID", "score",
"test", "age"), class = "data.frame", row.names = c("1", "2",
"3", "4"))

> frame2 <- structure(list(ID = structure(1:2, .Label = c("Guy1", "Guy2"),
class = "factor")),
.Names = "ID", class = "data.frame", row.names = c("1", "2"))

> merge(frame1, frame2, by = "ID"))
    ID score test age
1 Guy1    10    1  20
2 Guy1    13    2  20
3 Guy2     9    1  33
4 Guy2    11    2  33

> subset(frame1, ID %in% frame2$ID, select = c(ID, age))
    ID age
1 Guy1  20
2 Guy1  20
3 Guy2  33
4 Guy2  33

See ?subset and ?merge for more information.

HTH,
Jorge.-


On Sat, Jan 14, 2012 at 3:51 PM, jdog76 <> wrote:

>  I am positive this problem has a very simple solution, but I have been
> unable to find it, so I am asking for your help. I need to know how to look
> something up in one data frame and add it as a column in another.  If I
> have
> a data frame that looks like this:
>
> > frame1
>  ID  score  test age
> 1  Guy1 10 1  20
> 2 Guy1 13 2  20
> 3 Guy2 9 1  33
> 4 Guy2 11 2  33
>
> and another frame that looks like this:
>
> > frame2
>  ID
> 1 Guy1
> 2 Guy2
>
> How do I add a column to frame2 so it looks like this:
>
>  ID age
> 1 Guy1 20
> 2 Guy2 33
>
> I know this must be simple, but I couldn't find the solution by searching.
>
> thanks so much
> Jeremy
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/add-column-with-values-found-in-another-data-frame-tp4295626p4295626.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> 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]]

