0

I am trying to sort through a data frame and add rows that fit a criteria to vector. I want to take lines that start with '>MPMxx' where x is any integer, and put that line into one vector and the line below it into another vector. How can I represent the xx such that the program will just look for any integers in the place of x. Want to use a for loop with if statements. I have this thus far before I got stuck with the question.

for( i in 1:df$V1){
  if (df$V1 == MPMxx){
Name_vector <- df$V1[i] && Sequence <- df$V1[i+1]
}
}
  • 1
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Nov 03 '22 at 16:47
  • Can you say more what you mean by "put that line into one vector and the line below it into another vector"? Your first sentence makes it sound like you want to add rows within the data frame, ie make the vectors in that data frame longer. – Jon Spring Nov 03 '22 at 17:01
  • Greetings! Usually it is helpful to provide a minimally reproducible dataset for questions here so people can troubleshoot your problems (rather than a table or screenshot for example). One way of doing this is by using the `dput` function on the data you are using and pasting the output into your question. You can find out how to use it here: https://youtu.be/3EID3P1oisg – Shawn Hemelstrand Nov 16 '22 at 07:26

0 Answers0