[R] Data manipulation
Helmut Kudrnovsky
hellik at web.de
Wed Feb 9 07:33:06 CET 2005
thanks a lot for the information, reshape did the job
> datars <-reshape(data, timevar="TERRCODE", idvar="BID", direction="wide")
greetings
helli
BID TERRCODE ANMCODE
200310413120660 22 0
200310413120660 273 0
200310413120660 280 0
200310413120660 467 0
200310413120660 468 0
200310413127001 5 0
200310413127001 50 0
200310413127001 53 13
200310413127001 54 11
200310413127001 72 0
200310413127001 89 0
200310413127001 671 0
200310413225032 1 0
200310413225032 3 0
200310413225032 6 0
200310413225032 51 0
200310413225032 52 21
200310413225032 53 21
200310413225032 54 21
200310413225032 55 13
200310413225032 57 11
200310413225032 72 0
....
result:
BID ANMCODE.1 ANMCODE.2 ANMCODE.3 ANMCODE.4 ANMCODE.5 ANMCODE.6 ANMCODE.7 ....
200310413120660 NA NA NA NA NA NA NA NA NA NA NA NA
200310413127001 NA NA NA NA 0 NA NA NA NA NA NA NA
200310413225032 0 NA 0 NA NA 0 NA NA NA NA NA NA
200310413225033 0 NA 0 NA NA 0 NA NA NA NA NA NA
200310413225072 0 NA 0 NA NA NA NA NA 0 NA NA 0
200310413225073 0 NA 0 NA NA 0 NA NA NA NA 0 NA
200310413225074 0 NA 0 NA NA 0 NA NA NA NA NA 0
...
Eric Lecoutre <lecoutre at stat.ucl.ac.be> schrieb am 08.02.05 08:55:46:
Hi,
Have a look at:
? aggregate
? reshape
Eric
At 07:39 8/02/2005, you wrote:
>Content-Type: text/plain; charset="iso-8859-1"
>Received-SPF: none (hypatia: domain of hellik at web.de does not designate
>permitted sender hosts)
>X-Virus-Scanned: by amavisd-new at stat.math.ethz.ch
>Content-Transfer-Encoding: 8bit
>X-MIME-Autoconverted: from quoted-printable to 8bit by
>hypatia.math.ethz.ch id j186djX0017423
>X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on
>hypatia.math.ethz.ch
>X-Spam-Level:
>X-Spam-Status: No, score=-1.0 required=5.0 tests=AWL,BAYES_50 autolearn=no
>version=3.0.2
>
>Hi R-friends,
>
>i have large dataset in the following structure:
>
>BID;TERRCODE;ANMCODE
>200310413290002;4;0
>200310413290002;80;0
>200310413290002;2;0
>200310413290002;5;0
>200310413290003;3;0
>200310413290003;1;0
>200310413290003;11;0
>200310413290003;26;0
>200310413290003;141;21
>200310413290003;472;0
>200310413290004;3;0
>200310413290004;1;0
>200310413290004;7;0
>200310413290004;18;0
>200310413290004;51;0
>200310413290004;56;0
>200310413290004;57;0
>200310413290004;76;0
>200310413290004;89;0
>200310413290004;97;0
>200310413290004;98;0
>200310413290004;72;0
>200310413290004;456;0
>200310413290004;141;0
>200310413290004;640;0
>200310413290004;201;0
>200310413290004;764;20
>200310413290005;273;22
>200310413290005;456;0
>200310413290005;22;0
>200310413290005;23;0
>200310413290005;21;21
>200310413290005;141;0
>200310413290005;640;0
>200310413290005;201;0
>200310413290005;43;0
>200310413290005;650;0
>200310413290005;472;0
>200310413290006;456;0
>200310413290006;22;25
>200310413290006;23;25
>200310413290006;21;25
>200310413290006;640;0
>200310413290006;201;0
>200310413290006;43;0
>200310413290006;651;1
>.
>.
>.
>
>BID is the code of my sample-area
>TERRCODE is the code for landscape characteristic for example: 640 ... sun
>exposed, .....
>ANMCODE ist the value of the TERRCODE: for example 0 means "occuring", 1
>means "often occuring", ......
>
>Now my question: is it possible to get a table with the folllowing structure:
>
>
>BID (TERRCODE)4 .... (TERRCODE)21 ......
>200310413290002 (ANMCODE)0 .... (ANMCODE)0 .......
>200310413290003 0 .... 0 ......
>200310413290004 0 .... 0 ......
>200310413290005 0 .... 21 ......
>200310413290006 0 ..... 25 ......
>.
>.
>
>in this example (TERRCODE) and (ANMCODE) is only for explanation and not
>necessary for further analysis
>
>
>greetings from the snowy tyrol
>
>helli
>
>platform i386-pc-mingw32
>arch i386
>os mingw32
>system i386, mingw32
>status
>major 2
>minor 0.0
>year 2004
>month 10
>day 04
>language R
>
>______________________________________________________________
>Verschicken Sie romantische, coole und witzige Bilder per SMS!
>
>______________________________________________
>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
Eric Lecoutre
UCL / Institut de Statistique
Voie du Roman Pays, 20
1348 Louvain-la-Neuve
Belgium
tel: (+32)(0)10473050
lecoutre at stat.ucl.ac.be
http://www.stat.ucl.ac.be/ISpersonnel/lecoutre
If the statistics are boring, then you've got the wrong numbers. -Edward
Tufte
More information about the R-help
mailing list