File: r.rst

package info (click to toggle)
python-agate 1.13.0-1~exp1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 2,008 kB
  • sloc: python: 8,578; makefile: 126
file content (146 lines) | stat: -rw-r--r-- 2,421 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
=========
Emulate R
=========

c()
===

Agate's :meth:`.Table.select` and :meth:`.Table.exclude` are the equivalent of R's :code:`c` for selecting columns.

R:

.. code-block:: r

    selected <- data[c("last_name", "first_name", "age")]
    excluded <- data[!c("last_name", "first_name", "age")]

agate:

.. code-block:: python

    selected = table.select(['last_name', 'first_name', 'age'])
    excluded = table.exclude(['last_name', 'first_name', 'age'])

subset
======

Agate's :meth:`.Table.where` is the equivalent of R's :code:`subset`.

R:

.. code-block:: r

    newdata <- subset(data, age >= 20 | age < 10)

agate:

.. code-block:: python

    new_table = table.where(lambda row: row['age'] >= 20 or row['age'] < 10)

order
=====

Agate's :meth:`.Table.order_by` is the equivalent of R's :code:`order`.

R:

.. code-block:: r

    newdata <- employees[order(last_name),]

agate:

.. code-block:: python

    new_table = employees.order_by('last_name')

merge
=====

Agate's :meth:`.Table.join` is the equivalent of R's :code:`merge`.

R:

.. code-block:: r

    joined <- merge(employees, states, by="usps")

agate:

.. code-block:: python

    joined = employees.join(states, 'usps')

rbind
=====

Agate's :meth:`.Table.merge` is the equivalent of R's :code:`rbind`.

R:

.. code-block:: r

    merged <- rbind(first_year, second_year)

agate:

.. code-block:: python

    merged = agate.Table.merge(first_year, second_year)

aggregate
=========

Agate's :meth:`.Table.group_by` and :meth:`.TableSet.aggregate` can be used to recreate the functionality of R's :code:`aggregate`.

R:

.. code-block:: r

    aggregates = aggregate(employees$salary, list(job = employees$job), mean)

agate:

.. code-block:: python

    jobs = employees.group_by('job')
    aggregates = jobs.aggregate([
        ('mean', agate.Mean('salary'))
    ])

melt
====

Agate's :meth:`.Table.normalize` is the equivalent of R's :code:`melt`.

R:

.. code-block:: r

    melt(employees, id=c("last_name", "first_name"))

agate:

.. code-block:: python

    employees.normalize(['last_name', 'first_name'])

cast
====

Agate's :meth:`.Table.denormalize` is the equivalent of R's :code:`cast`.

R:

.. code-block:: r

    melted = melt(employees, id=c("name"))
    casted = cast(melted, name~variable, mean)

agate:

.. code-block:: python

    normalized = employees.normalize(['name'])
    denormalized = normalized.denormalize('name')