1

I have a problem with an unstructured text. I have a data frame made by a single column divided in multiple rows, that i won't show here for simplicity. I create a simple example to describe better what i am trying to do:

DATA
grey
blue
yellow
green
white
black

I need to extract the SINGLE row, after the one containing the word that i select. Example, the word "blue" is my "topic"; i want to extract only the SINGLE row following it, obtaining "yellow". How could i do? Thank you for your future suggestions.

Sotos
  • 51,121
  • 6
  • 32
  • 66
Silvia
  • 405
  • 4
  • 17
  • 5
    If your data frame is `df` and the column `V1`, then simply `df$V1[which(df$V1 == 'blue')+1]`. Also You "have a problem with unstructured text in R"...not Rstudio – Sotos Apr 19 '17 at 14:29
  • 1
    Please give the definition of your data or use `dput()` to show your data. [mcve] and http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – jogo Apr 19 '17 at 14:29

1 Answers1

0

There is a little lack of information here but I'll explain what you can do in both the cases.

Case1 The column you have is itself is rownames of your database.

You can check by doing

row.names(dataframe)

In this case, just add one more column in your dataframe for row numbers and then you can search for your value and take the next data by giving the number.

Case2 When there is a column in which u have this data. Then just do

a = row.name(df[df$col1=="blue",])
b= df[a+1,1]

b would be your yellow.

Let me know if this solves the problem

tacky_ops
  • 1
  • 1