Professional Documents
Culture Documents
Data Manipulation With R - 2
Data Manipulation With R - 2
Data Manipulation With R - 2
CHAINING
B
1
2
3
4
5
6
Or by chaining:
DATA.TABLE
DATA.TABLE
Lets practice
DATA.TABLE
DATA.TABLE
DATA.TABLE
Lets practice
1:
2:
3:
4:
5:
x y
1 6
1 7
1 8
2 9
2 10
RHS
1:
2:
3:
4:
5:
x
2
2
1
1
1
y z
6
7
8
9
10
10
9
8
7
6
DT[, x := rev(x)]
DATA.TABLE
1:
2:
3:
4:
5:
x
2
2
1
1
1
y
6
7
8
9
10
z
10
9
8
7
6
a
10
9
8
7
6
DT[, y := NULL]
DATA.TABLE
> DT
1:
2:
3:
4:
5:
x
2
2
1
1
1
y
6
7
8
9
10
z
10
9
8
7
6
a
10
9
8
7
6
y
DT[, paste0(colNamePrefix", 1:4) := NULL ]
DATA.TABLE
Functional :=
> DT
1:
2:
3:
4:
5:
x
2
2
1
1
1
y
6
7
8
9
10
z
1
1
1
1
1
DATA.TABLE
# y (kg)
1:
2:
3:
4:
5:
x y
2 6
2 7
1 8
1 9
1 10
> DT[2:4,
2:4 z := sum(y), by = x]
z
NA
NA
17
NA
NA
17
NA
DATA.TABLE
DATA.TABLE
Lets practice
set()
DATA.TABLE
> DT
1:
2:
3:
4:
5:
x
1
2
3
4
5
y
1
8
1
1
1
z
2
5
4
2
3
1:
2:
3:
4:
5:
x
1
2
3
4
5
y
1
8
1
1
1
z
2
3
4
5
6
setnames()
> setnames(DT, y, z))
> DT
1:
2:
3:
4:
5:
x
1
2
3
4
5
DATA.TABLE
y
a
b
c
d
e
1:
2:
3:
4:
5:
x
1
2
3
4
5
z
a
b
c
d
e
setcolorder()
> setcolorder(DT, c(y, x))
> DT
1:
2:
3:
4:
5:
x
1
2
3
4
5
y
a
b
c
d
e
1:
2:
3:
4:
5:
y
a
b
c
d
e
x
1
2
3
4
5
DATA.TABLE
DATA.TABLE
Lets practice