I have data (imported imperfectly from a PDF) that has everything in a single column, with certain rows as descriptive headers. For example:
dfx <- data.frame(V1 = c("Box 1", "abcd10", "bcde15", "Box 2", "cdefg35", "jklm40", "nopq50", "rstu52"))
V1
1 Box 1
2 abcd10
3 bcde15
4 Box 2
5 cdefg35
6 jklm40
7 nopq50
8 rstu52
I want to create a separate column where each observation takes on the value of the nearest heading above it. Like this:
V1 v2
1 abcd10 Box 1
2 bcde15 Box 1
3 cdefg35 Box 2
4 jklm40 Box 2
5 nopq50 Box 2
6 rstu52 Box 2
Nothing I've tried has gotten me close. Any help would be appreciated. Thanks!