Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8104393
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T23:49:35+00:00 2026-06-05T23:49:35+00:00

In my dataframe there is a column with Sound and Response as values. Ideally,

  • 0

In my dataframe there is a column with “Sound” and “Response” as values. Ideally, the pattern is two Sounds followed by one Response. But, it can happen that there are three Sounds followed by a Response.

How can I tell R to raise a flag whenever it finds this pattern in my data? I need to look at each case individually before I can delete the third Sound-row.

>df <- data.frame(V1=rep("SN", 7),  
             V3=c("Sound", "Sound", "Response", "Sound", "Sound", "Sound", "Response"), 
             V4=c("XYZc02i03", "XYZq02i03", 200, "ZYXc01i30", "ZYXq01i30", "ZYXc01i35", 100), 
             stringsAsFactors=FALSE) 

V1       V3        V4
SN    Sound XYZc02i03
SN    Sound XYZq02i03
SN Response       200
SN    Sound ZYXc01i30
SN    Sound ZYXq01i30
SN    Sound ZYXc01i35
SN Response       100     

So, after finding three consecutive Sounds and deleting the last one of them (i. e. the one just before the folowing Response), I should have the desired pattern like this:

V1       V3        V4
SN    Sound XYZc02i03
SN    Sound XYZq02i03
SN Response       200
SN    Sound ZYXc01i30
SN    Sound ZYXq01i30
SN Response       100  

I’m sorry that I keep posting these basic questions. Any ideas are, as always, greatly appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T23:49:37+00:00Added an answer on June 5, 2026 at 11:49 pm
    cumsum(rle(df$V3)$lengths)[rle(df$V3)$lengths == 3]
    [1] 6
    

    this returns the vector of positions where “Sound” is third in a row. Now you can easily delete them or make some column to mark these positions.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a method for moving a column from one position in a data.frame
Say I have a dataframe df with two or more columns, is there an
I am looking to remove multiple observations from one column within a dataframe based
Please excuse me if there are already answers to this, but I can't quite
I have an R dataframe and I'm trying to subtract one column from another.
I know there is an easy way to do this...but, I can't figure it
I have a column in a dataframe where the values are letter-number combinations like
Is there any way to preserve spaces in a data.frame's column names when calling
I have a data.frame (X,Y,a,b,c,d,e) Is there a package where I can predict both
I have a dataframe x with this values: x1 x2 x3 1 NA 4

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.