list manipulation - How do I replace a missing value in a column with the value immediately above throughout a table?
I have a large table (7000 rows × 17 columns) of terse textual data. In many of the columns, empty entries have been replaced with "." as a marker. Working from the top of the columns downward, I want to replace each successive "." with the data value (non-".") from above until the next data value is found; at which time I want to replace the next sequence of "." with the new data value etc. E.g.
x --> x
"." --> x
y --> y
"." --> y
"." --> y
z --> z
"." --> z
I need to do this for all rows of data. Any help would be greatly appreciated. -k-
Answer
How about
f[_, y_] := y
f[x_, "."] := x
fill[data_] := Transpose[FoldList[f, First[#], Rest[#]] & /@ Transpose[data]]
Comments
Post a Comment