Hi everybody!
I have a dataset like this:
Df <- data.frame(A=c(2,3,9,12,2,5,7,7,1,23,3,4,14,3,9,8,6,11,9,4),B=c(1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2))
Df
> Df
A B
1 2 1
2 3 1
3 9 1
4 12 1
5 2 1
6 5 1
7 7 1
8 7 1
9 1 1
10 23 1
11 3 2
12 4 2
13 14 2
14 3 2
15 9 2
16 8 2
17 6 2
18 11 2
19 9 2
20 4 2
What I want is a dataset like this:
Df2 <- data.frame(A=c(2,3,9,12,2,5,7,7,1,23), B=c(3,4,14,3,9,8,6,11,9,4))
Df2 = t(Df2)
Df2 <- as.data.frame(Df2)
Df2
> Df2
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10
A 2 3 9 12 2 5 7 7 1 23
B 3 4 14 3 9 8 6 11 9 4
So my goal is to transpose the column A in Df in Df2 and divide it in two rows according to the counter of column B in Df.
I try this command, but I don't know how to complete it:
Df %>% rowwise() %>% mutate(Pos=which(c_across(A:B) ??? )[1])
Thanks