I have a string whose structure and length can keep varying, that is
Input:
X <- ("A=12&B=15&C=15")
Y <- ("A=12&B=15&C=15&D=32&E=53")
What I was looking for this string to convert to data frame
Output Expected:
Dataframe X
A B C
12 15 15
and Dataframe Y
A B C D E
12 15 15 32 53
What I tired was this:
X <- as.data.frame(strsplit(X, split="&"))
But this didn't work for me, as it created only one column and column name was messed up.
P.S: I cannot hard code the column names because they can vary, and at any given time a string will contain only one row
eval(parse(text=paste("data.frame(",gsub("&", ",", X),")")))I feel bad for suggesting it, but maybe it isn't all that horrible in the current context.