I have a very large data frame but the gist of the variable that I am interested in looks like this:
A B
1 DW
2 DI
3 RW
4 RI
5 DW
6 RI
7 RW
8 DI
I want to break up variable B
such that I create a variable that would reflect only the first letter in B
and a variable that reflects only the last letter in B
.
To that end, my data frame would have 2 additional variables, resulting in something that looks like this
A B C D
1 DW D W
2 DI D I
3 RW R W
4 RI R I
5 DW D W
6 RI R I
7 RW R W
8 DI D I
My data frame has over 100,000 lines. How can I get R to do this automatically?
Thank you for your help!