I am doing some coding in R
and I am dealing with cases where some data frames are coded as individual strings, and it is necessary to be able to recover the data frames from the strings. The strings are in this form:
|Carrot^14|Cucumber^3|Potato^8|
The seperator |
separates the rows of the data frame and the separator ^
separates the column with the character value from the column with the numeric value. (To simplify the problem, note that these symbols appear only as separators --- they never appear in the values in the data frame.) The data frame corresponding to this string would be:
Vegetable Quantity
"Carrot" 14
"Cucumber" 3
"Potato" 8
I would like to be able to decode a string to extract the data frame that it encodes. I know that this will require some kind of regexp
query, but I'm not quite sure how to do it. I am also not sure if this kind of correspondence between a data frame and a single string has any particular name that would lead me to further information about the technique.
My Questions: Does this kind of coding from a data frame to a single string (and back) have a particular name? How can I decode the string in R
?