[R-sig-Geo] Data Manipulation

Barry Rowlingson b.rowlingson at lancaster.ac.uk
Sat Dec 8 18:33:13 CET 2012


You are converting from 'long' to 'wide' format. This is probably
something that the 'reshape' package will do for you. Install it, and
check out the 'melt' and 'cast' functions.

 Also, you are asking a non-geo question on the geo mailing list. You
should try asking on R-help (but read the posting guide first).

You could also try asking on stackoverflow (stackoverflow.com),
tagging your question with 'R'.

 However you ask, a reproducible example is always welcome. We don't
like to have to reconstruct your data objects manually...


On Sat, Dec 8, 2012 at 4:30 PM, Benno Dillinger
<benno.dillinger at gmail.com> wrote:
> Dear all,
>
> I'm new to R and I have a question regarding data manipulation:
>
> I have a 2 column dataframe with
> ID        value
> 1        1
> 1        2
> 2        3
> 2        4
> 3        5
> 3        6
>
> I would like to create a dataframe that looks like
>
> ID        value1        value2
> 1        1                    2
> 2        3                    4
> 3        5                    6
>
> Any suggestions how to do this?
>
>
> Additionally, is it possible for the 'numbers' to have different
> lengths, in sense of one ID having 3 entries an still being able to
> perform the (hopefully) suggested operation?
>
> ID        value
> 1        1
> 1        2
> 1        2.5
> 2        3
> 2        4
> 3        5
> 3        6
>
> ==>
> ID        value1        value2        value3
> 1        1                    2               2.5
> 2        3                    4               NA
> 3        5                    6               NA
>
> Any help would be appreciated.
>
> Regards
>
> Benno
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo



More information about the R-sig-Geo mailing list