Try this:
DF[unlist(tapply(rownames(DF), DF$id, function(x) c(x, x[1]))),]
On 8/9/06, Leonardo Lami <lami at faunalia.it>
wrote:> Hi all,
> I have a simple question:
> I have a data.frame like this:
>
> id x y
> 1 50 1647685 4815259
> 2 50 1647546 4815196
> 3 50 1647454 4815294
> 4 50 1647405 4815347
> 5 50 1647292 4815552
> 6 50 1647737 4815410
> 7 74 1647555 4815201
> 8 74 1647464 4815023
> 9 74 1646970 4815129
> 10 74 1646895 4815264
> 11 74 1646762 4815513
>
> and I'd like to trasform it with the "convert.to.shapefile"
function
> (shapefiles package) but to make this I must have a data.frame like this:
>
> id x y
> 1 50 1647685 4815259
> 2 50 1647546 4815196
> 3 50 1647454 4815294
> 4 50 1647405 4815347
> 5 50 1647292 4815552
> 6 50 1647737 4815410
> 7 50 1647685 4815259
> 8 74 1647555 4815201
> 9 74 1647464 4815023
> 10 74 1646970 4815129
> 11 74 1646895 4815264
> 12 74 1646762 4815513
> 13 74 1646762 4815513
>
> with the first point of every id repeated to close the polygon.
> There is a function to make this indipendently by the number of the id
>
> Best regards
> Leonardo
>
> --
> Leonardo Lami
> email + jabber: lami at faunalia.it
> www.faunalia.it
> Cell: (+39)349-1310164 Tel+Fax: (+39) 0587-213742
> Piazza Garibaldi 5 - 56025 Pontedera (PI), Italy
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
>