Hi I'm trying to extract some information from a chemical formula and add them to a pre-existing table on r. Currently I have a column that have chemical formulas as shown (C4H8O2). I have no problem extracting each element and its corresponding number. However I have a problem when brackets are involved in the formula, such as C3[13]C1H8O2. I want the title to say 13[C] and the input be 1. However my code doesn't recognize '[13]C1' so it gives me an error.
Any suggestions would be great.
#First manipuation - extracting information out of the "Composition" column, into seperated columns for each element
data2 <- dataframe%>%mutate(Composition=gsub("\\b([A-Za-z]+)\\b","\\11",Composition),
name=str_extract_all(Composition,"[A-Za-z]+"),
value=str_extract_all(Composition,"\\d+"))%>%
unnest()%>%spread(name,value,fill=0)
I already have a pre-made csv file that has the table organized and I made that into a data frame, so now I'm just trying to parce out the elements with the the 'C' column and '[13]C' column and their corresponding number.