Skip to content
Prev 284648 / 398502 Next

"unsparse" a vector

Suppose I have a vector of strings:
c("A1B2","A3C4","B5","C6A7B8")
[1] "A1B2"   "A3C4"   "B5"     "C6A7B8"
where each string is a sequence of <column><value> pairs
(fixed width, in this example both value and name are 1 character, in
reality the column name is 6 chars and value is 2 digits).
I need to convert it to a data frame:
data.frame(A=c(1,3,0,7),B=c(2,0,5,8),C=c(0,4,0,6))
  A B C
1 1 2 0
2 3 0 4
3 0 5 0
4 7 8 6

how do I do that?
thanks.