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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:17:03+00:00 2026-06-17T20:17:03+00:00

I have the following dataframe (below) which is a subset of my full dataset.

  • 0

I have the following dataframe (below) which is a subset of my full dataset. I need to define the same ID for each entries with the same LAT/LONG and landed date. I previously ordered LANDEDDATE from the earliest to latest date.

 > dput(df2)
structure(list(LATITUDE = c(43.35, 43.35, 43.35, 43.35, 43.35, 
43.35, 43.35, 43.35, 43.5166, 43.5166, 43.5166, 43.5166, 43.5166, 
43.5166, 43.5166, 42.9833, 42.9833, 42.9833, 42.9666, 42.9666
), LONGITUDE = c(-60.6163, -60.6165, -60.7167, -60.7166, -60.7163, 
-60.716, -60.7169, -60.7166, -59.9169, -59.9168, -59.9169, -59.9166, 
-59.9166, -59.916, -59.916, -61.8333, -61.8333, -61.8333, -61.9161, 
-61.9161), LANDEDDATE = structure(c(11171, 11171, 11183, 11183, 
11183, 11183, 11183, 11183, 11192, 11192, 11192, 11192, 11192, 
11192, 11192, 11210, 11210, 11210, 11210, 11210), class = "Date"), 
    sppCODE = c(251L, 251L, 251L, 251L, 251L, 251L, 251L, 251L, 
    251L, 251L, 251L, 251L, 251L, 256L, 251L, 256L, 252L, 251L, 
    251L, 252L), LIVEW = c(0.337, 0.471, 0.238, 0.772, 0.178, 
    0.416, 0.535, 0.356, 0.442, 0.663, 0.442, 0.497, 0.276, 0.032, 
    0.828, 0.035, 0.011, 1.224, 1.025, 0.072), SPECIES = structure(c(7L, 
    7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
    7L, 7L, 7L, 7L), .Label = c("Albacore Tuna", "Bigeye Tuna", 
    "Bluefin Tuna", "Mako", "Porbeagle", "Shark, UNSP", "Swordfish", 
    "Tuna, UNSP", "White Marlin", "Yellowfin Tuna"), class = "factor")), .Names = c("LATITUDE", 
"LONGITUDE", "LANDEDDATE", "sppCODE", "LIVEW", "SPECIES"), row.names = c(19L, 
20L, 13L, 14L, 15L, 16L, 17L, 18L, 6L, 7L, 8L, 9L, 10L, 11L, 
12L, 1L, 2L, 3L, 4L, 5L), class = "data.frame")

This is what I’ve done so far but I can’t figure out the rest.

    df2$setID<-"NA" #I created an empty setID.
    > head(df2)
   LATITUDE LONGITUDE LANDEDDATE sppCODE LIVEW   SPECIES setID
19    43.35  -60.6163 2000-08-02     251 0.337 Swordfish    NA
20    43.35  -60.6165 2000-08-02     251 0.471 Swordfish    NA
13    43.35  -60.7167 2000-08-14     251 0.238 Swordfish    NA
14    43.35  -60.7166 2000-08-14     251 0.772 Swordfish    NA
15    43.35  -60.7163 2000-08-14     251 0.178 Swordfish    NA
16    43.35  -60.7160 2000-08-14     251 0.416 Swordfish    NA
unique<-df2[which(!duplicated(df2[,1:3])),] #This is each entry that are NOT duplicate
unique2$setID<-1:13 # Ranked from 1:13
> head(unique) #looks like that
   LATITUDE LONGITUDE LANDEDDATE sppCODE LIVEW   SPECIES setID
19    43.35  -60.6163 2000-08-02     251 0.337 Swordfish     1
20    43.35  -60.6165 2000-08-02     251 0.471 Swordfish     2
13    43.35  -60.7167 2000-08-14     251 0.238 Swordfish     3
14    43.35  -60.7166 2000-08-14     251 0.772 Swordfish     4
15    43.35  -60.7163 2000-08-14     251 0.178 Swordfish     5
16    43.35  -60.7160 2000-08-14     251 0.416 Swordfish     6
rep<-df2[which(duplicated(df2[,1:3])),] #This is all my replicates

I need to allocate the setID of my unique dataframe to the corresponding sets (replicates with same LAT/LONG and LANDEDDATE) in the rep dataframe. Any advices would be 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-17T20:17:04+00:00Added an answer on June 17, 2026 at 8:17 pm

    That sounds like a lot of wrangling!

    Why not create a “key” with something like paste

    paste(df2$LONGITUDE, df2$LATITUDE, df2$LANDEDDATE)
    

    then you can use factor and coerce it back to its underlying integers:

    df2$setID <- as.integer(factor(paste(df2$LONGITUDE, df2$LATITUDE, df2$LANDEDDATE)))
    

    You could also do this with data.table if your data is large (or even if its not!).

    library(data.table)
    df2 <- data.table(df2, key=c('LATITUDE', 'LONGITUDE', 'LANDEDDATE'))
    
    df2[, setID := (.GRP), by=c('LATITUDE', 'LONGITUDE', 'LANDEDDATE')]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a DataFrame with the following structure: <class 'pandas.core.frame.DataFrame'> DatetimeIndex: 3333 entries, 2000-01-03
I have the following dataset (see for loading dataset below) ID Date qty 1
I have the following dataframe df <- data.frame( Type=rep(LETTERS[1:6],3), Level=rep(1:3,each=6), Value=1:18) I'd like to
I have the following dataframe: sp <- combn(c(sp1,sp2,sp3,sp4),2) d <- data.frame(t(sp),freq=sample(0:100,6)) and two factors
I have the following dataframe: DF <- data.frame(x = c(1, 2, 3,NA), y =
I have a Multindex DataFrame with the following structure: 0 1 2 ref A
I have the following pandas Dataframe: from pandas import DataFrame, MultiIndex index = MultiIndex.from_tuples(zip([21,22,23],[45,45,46]),
I have very large dataframe and I need to choose variable number satisfying certain
I have a dataset with about 3 million rows and the following structure: PatientID|
Suppose I have the following DataFrame (timeseries, first column is a DateTimeIndex) atn file

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.