I have one data frame (let it be called df) looks like this:
col1 <- c("1/10", "2/30", "1/40", "3/23", "0/17", "7/14")
col2 <- c("2/44", "0/13", "4/55", "6/43", "0/19", "2/34")
col3 <- c("0/36", "0/87", "3/11", "2/12", "4/33", "0/12")
col4 <- c("1/76", "2/65", "2/21", "5/0", "2/26", "1/52")
df <- data.frame(col1,col2,col3,col4)
GOAL . Each cell has two numbers separated by a "/" character. Create two data frames: 1 data frame with a LEFT number and another data frame with a RIGHT number.
The end result would ideally look like this:
df.left.numbers:
col1 col2 col3 col4
1 2 0 1
2 0 0 2
1 4 3 2
3 6 2 5
0 0 4 2
7 2 0 1
df.right.numbers:
col1 col2 col3 col4
10 44 36 76
30 13 87 65
40 55 11 21
23 43 12 0
17 19 33 26
14 34 12 53
I used strsplit (), but to split 1 column into two in the same data frame. I also tried the separate () function in the tidyr package, but this requires the name of this column. I repeat them all. I suppose I could write a loop, however I was wondering if anyone has an easier way to do this!
Thank!!