Hi Laura,
The function merge() works well, but another elegant to do it would
involve match().
(Assuming your data.frame object is called x)
x$motherAge <- with(x, age[match(mothers.I.D,I.D)])
Cheers,
--
*Luc Villandré*
/Biostatistician
McGill University Health Center -
Montreal Children's
x <- "I.D age 'MID'
01 5 03
02 6 06
03 16 NA
04 8 06
05 3 NA
06 17 NA"
xx <- read.table(textConnection(x), header=TRUE); xx
closeAllConnections()
ag1 <- xx[, c(1,2)] ; ag1
ag2 <- xx[, c(1,3)] ; ag2
names(ag2[2]) <- "I.D"
merge(ag1,ag
Kubasiewicz, Laura imperial.ac.uk> writes:
> I have a dataframe with columns for...
>
> 'I.D' 'age' 'mothers I.D'
> 01 5 03
> 02 6 06
> 03 16 NA
> 04 8 06
> 05 3 NA
> 06 17 NA
>
> I need to create a new column for 'mothers age' which put
3 matches
Mail list logo