[R] copy the columns based on the code
Rui Barradas
rui1174 at sapo.pt
Mon Mar 26 16:26:30 CEST 2012
Hello,
>
> The problem is that it gives the result that I want
>
Oh dear, it shouldn't?
>
> The idea is based on the column of source and intended Identify the
> cities and put a new data structure
>
> The idea is something like this.
> pos Source city Destine city_destine
> 1 1 Barcelona 2 Madrid
> 1 1 Barcelona 3 Lisbon
> 2 3 Lisbon 4 Milan
> 3 2 Madrid 4 Milan
>
Try the following.
temp1 <- merge(travel, city, by.x='Source', by.y='cod')
temp2 <- merge(temp1, city, by.x='Destine', by.y='cod')
temp2[, c(3, 2, 4, 1, 5)]
The general idea is obvious, I believe: you want to relate 'cod/city' from
table 'city' with
two columns of table 'travel', one is source and the other is destine. So
you need to merge the tables twice.
Hope this helps,
Rui Barradas
--
View this message in context: http://r.789695.n4.nabble.com/copy-the-columns-based-on-the-code-tp4505253p4505985.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list