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 7509041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:47:33+00:00 2026-05-29T22:47:33+00:00

I have a dataframe with 6 columns and many rows that includes positions for

  • 0

I have a dataframe with 6 columns and many rows that includes positions for an individual tagged fish. The structure is as follows:

head(tag.29912)

 Date.and.Time..UTC.    Receiver    Transmitter Latitude Longitude ndiffs29912
1    07/10/2010 15:53 VR2W-107619 A69-1303-29912 48.56225 -53.89144          NA
2    07/10/2010 15:56 VR2W-107619 A69-1303-29912 48.56225 -53.89144         180
3    07/10/2010 16:00 VR2W-107619 A69-1303-29912 48.56225 -53.89144         240
4    07/10/2010 16:24 VR2W-107619 A69-1303-29912 48.56225 -53.89144        1440
5    07/10/2010 16:45 VR2W-104556 A69-1303-29912 48.56460 -53.88956        1260
6    07/10/2010 16:47 VR2W-107619 A69-1303-29912 48.56225 -53.89144         120

The ndiffs29912 refers to the difference in time between detections – hence the first row has an NA because there is nothing previous to calculate a time difference with.

I would like to filter out any single detections that occur over 24 hours (86400sec), because these are likely spurious. I have tried the following code to try and remove them:

for (i in 1:length(tag.29912)) { 
if (tag.29912[i,6]>=86400 & tag.29912[i+1,6]>=86400) 
{rm(i)}

This has not worked. I have also tried:

for (i in 1:length(tag.29912)) { 
if (tag.29912[i,6]>=86400 & tag.29912[i+1,6]>=86400) 
{new<-tag.29912[i,]}
else{filteredtag.29912<-as.data.frame(tag.29912[-new])}
}  

to no avail. Ultimately, I would like a new dataframe with all single detections removed.
Any tips would be 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-05-29T22:47:34+00:00Added an answer on May 29, 2026 at 10:47 pm

    A couple of things:

    1. A data frame is a list with some special requirements (i.e. each element of the list must be of the same length). One consequence of this is that length(tag.29912) should return the length of the list, i.e. the number of columns, whereas in your loop you probably intended to loop over the number of rows.

    2. You can pull out all these rows using vectorization, which is very very important to learn in R.

    3. rm() removes objects from your workspace, which is not what you’re trying to do.

    In your particular case you want to identify rows with values in the ndiffs29912 column with consecutive 86400 values and remove them.

    So something like

    tag.29912$flag <- FALSE
    for (i in 2:(nrow(tag.29912) - 1){
        if (tag.29912[i,6]>=86400 & tag.29912[i+1,6]>=86400){
          tag.29912$flag[i] <- tag.29912$flag[i+1] <- TRUE
        }
    }
    tag.29912 <- tag.29912[!tag.29912$flag,]  
    

    should give you what you want.

    But by the looks of this code, though, I strongly recommend that you take a few hours and carefully spend some time with a basic manual for beginners.

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

Sidebar

Related Questions

Suppose that you have a data frame with many rows and many columns. The
I have a dataframe with approximately 500,000 rows and four columns. The dataframe contains
I have a dataframe made up of 400'000 rows and about 50 columns. As
I have a dataframe with a column of integers that I would like to
I have a big dataframe with columns such as: ID, time, OS, IP Each
Say I have a dataframe df with two or more columns, is there an
I have a dataframe of 9 columns consisting of an inventory of factors. Each
I have a dataframe with columns labeled A,B & C. I want to add
I have a dataframe made up of 6 columns. Columns 1 to 5 each
I have a dataframe that looks like this DF: V1 V2 V3 V4 V5

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.