I have a dataframe like this:
I would like to split the second column into many columns based on "?". However, this is not easy, because there is another interrogative marker in the bite. Thus, the only additional distribution is that each substring contains "http".
How can you smash them? The number of columns in the output example is just an example that I donβt know exactly how much can be generated.
Sample input:
df_in <- data.frame(x = c('x1','x2','x3','x4'), y = c('http://example1.com?https://example2.com', 'NA', 'http://example3.com?id=1234?https://example4/com?http://example6.com', 'http://example5.com'))
console-printed dataframe:
df_in xy x1 http://example1.com?https://example2.com x2 NA x3 http://example3.com?id=1234?https://example4/com?http://example6.com x4 http://example5.com
An example of the expected result:
df_out <- data.frame(x = c('x1','x2','x3','x4'), col1 = c('http://example1.com', 'NA', 'http://example3.com?id=1234', 'http://example5.com'), col2 = c('https://example2.com', 'NA', 'https://example4/com', 'NA'), col3 = c('NA', 'NA', 'https://example6/com', 'NA'))
Output printed on console:
x col1 col2 col3 x1 http://example1.com https://example2.com NA x2 NA NA NA x3 http://example3.com?id=1234 https://example4/com https://example6/com x4 http://example5.com NA NA