I have a column of alphanumeric data containing data that looks like this K*01:01+K*01:02:01:01, K*77:01:08+K*01:02:01:22, K*10:01:77. I want to separate the data based on the strings before and after the + sign, new data should be displayed in 2 separate columns. I want my output to look like this:
column1 = K*01:01, K*77:01:08, K*10:01:77
column2 = K*01:02, K*01:02:01:02
I tried mydata$column1 <- sub("(.?)\+.", "\1", mydata$merged) works fine but when I used mydata$column2 <- sub(".\+(.?)", "\1", mydata$merged) for ID 3 K*10:01:77 is extracted both in columns 1 and 2, and I want column 2 to display a blank/empty cell for strings that do not have the + delimiter. Also I want the new columns to appear in the current data frame adjacent to the original merged column so packages like stringer do not work.