'Create a new line if cells equals a value from a dataframe

Using this dataframe:

            ##    doc_id paragraph_id sentence_id token_id       token      lemma  upos xpos
            ## 1    doc1            1           1        1 Linguistics Linguistic  NOUN  NNS
            ## 2    doc1            1           1        2        also       also   ADV   RB
            ## 3    doc1            1           1        3       deals       deal  NOUN  NNS
            ## 4    doc1            1           2        1   Something   something NOUN  NNS
            ## 5    doc1            1           2        2        Else        else NOUN  NNS

I'd like to have something like this in a .txt file:

Linguistic_NNS also_R deal_NN
something_NN else_NN

Except that using this code:

paste(text_anndf$lemma, "_", text_anndf$xpos, collapse = " ", sep = "")

I have this:

Linguistic_NN also_R deal_NN something_NN else_NN

Because it doesn't take into account the "sentence_id" values. Do I need to use a If or something similar ? Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source