I have a dataset with string rule set.
R> input
id rules
1 1 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
2 2 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
3 3 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
4 4 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
5 5 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
6 6 1.11=>0;1.12=>0;1.13=>0;1.14=>1;1.15=>0
7 7 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
8 8 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
9 9 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
10 10 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
11 11 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
12 12 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
13 13 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
14 14 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
15 15 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
16 16 1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0
What is the fastest way to split and join this rules as separate columns? Desired result:
R> res
R1.11 R1.12 R1.13 R1.14 R1.15 id
1 0 0 0 0 0 1
2 0 0 0 0 0 2
3 0 0 0 0 0 3
4 0 0 0 0 0 4
5 0 0 0 0 0 5
6 0 0 0 1 0 6
7 0 0 0 0 0 7
8 0 0 0 0 0 8
9 0 0 0 0 0 9
10 0 0 0 0 0 10
11 0 0 0 0 0 11
12 0 0 0 0 0 12
13 0 0 0 0 0 13
14 0 0 0 0 0 14
15 0 0 0 0 0 15
16 0 0 0 0 0 16
To reproduce the data sets see structures below.
Input data structure:
input <- structure(
list(id = 1:16,
rules = c("1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>1;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0",
"1.11=>0;1.12=>0;1.13=>0;1.14=>0;1.15=>0")),
.Names = c("id", "rules"),
row.names = c(NA, -16L),
class = "data.frame")
Output data structure:
output <- structure(
list(R1.11 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
R1.12 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
R1.13 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
R1.14 = c(0L, 0L, 0L, 0L, 0L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
R1.15 = c(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L),
id = 1:16),
.Names = c("R1.11", "R1.12", "R1.13", "R1.14", "R1.15", "id"),
class = "data.frame",
row.names = c(NA, -16L))