Given the following dataframe:
df <- structure(list(OTU = structure(c(1L, 2L, 3L, 4L, 5L, 1L, 2L,
3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L, 4L, 5L, 1L, 2L, 3L,
4L, 5L), class = "factor", .Label = c("OTU_1", "OTU_2", "OTU_3",
"OTU_4", "OTU_5")), read = structure(c(1L, 1L, 1L, 1L, 1L, 2L,
2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 5L, 5L,
5L, 5L, 5L), .Label = c("a", "b", "c", "d", "e"), class = "factor")), class = "data.frame", row.names = c(NA,
-25L))
OTU read
1 OTU_1 a
2 OTU_2 a
3 OTU_3 a
4 OTU_4 a
5 OTU_5 a
6 OTU_1 b
7 OTU_2 b
8 OTU_3 b
9 OTU_4 b
10 OTU_5 b
11 OTU_1 c
12 OTU_2 c
13 OTU_3 c
14 OTU_4 c
15 OTU_5 c
16 OTU_1 d
17 OTU_2 d
18 OTU_3 d
19 OTU_4 d
20 OTU_5 d
21 OTU_1 e
22 OTU_2 e
23 OTU_3 e
24 OTU_4 e
25 OTU_5 e
I would like to create an new dataframe as follows:
a b c d e
OTU_1 1 1 1 1 1
OTU_2 1 1 1 1 1
....
It´s not a perfect example because the values of the dataframe are always 1 but in my dataframe you have different number of letters.
How can i do that very fast as my dataframe is quite big (1.5M rows)??
Thanks