0

I have a dataset for which I want to create groups based on some marking values. As an example, the data set looks like thisinput

The values are ad in chronological sequence, with every value up to the value 'end' being one day. I'm trying to reorganise the data so that the values of the first column appear like this: output

At first, I assumed it would be a simple transpose problem, but I can't see any argument or parameter to specify that the groups are delimited by the value 'end'

As I type, it occurs to me that maybe a for loop could run through the values and reorganise them, using the 'end' value like a stop codon in DNA transcription, but I'd like to make sure the isn't a simpler way before I start down that road.

curly
  • 43
  • 1
  • 7
  • Images of data are not helpful. Please take a look at these tips on how to produce a [minimum, complete, and verifiable example](http://stackoverflow.com/help/mcve), as well as this post on [creating a great example in R](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – lmo Jun 07 '17 at 12:10

1 Answers1

1

How's this?

df <- data.frame(name = c("aa", 
                          "bb", 
                          "cc", 
                          "dd", 
                          "end", 
                          "ee", 
                          "ff", 
                          "gg", 
                          "end"))

unlist(strsplit(paste(df$name, collapse = " "), " end "))
Mist
  • 1,888
  • 1
  • 14
  • 21
  • You've perfectly answered the question I asked, but I failed to include an important requirement, which is the need to have a result such that it is possible to ask a question like " On what day(s), was Sally present with a man." Should open another question, or modify this one? – curly Jun 08 '17 at 14:24