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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T04:34:59+00:00 2026-05-29T04:34:59+00:00

G’day All, I am working in R. Sorry about this really basic question, but

  • 0

G’day All,

I am working in R. Sorry about this really basic question, but I am a bit stuck.
I have a data set of presence/absence point count data with date of count, and site number (see below). I would like to ultimately create a data.frame that collates all counts by grid cell number and has each visit to a site as a new visit (see below). I can’t figure out how to do this, so thought I would take an easier route and make a column that gives a visit number for each record. So, the column would give a number for each record by the date of the visit within each site group (see below). I can’t figure out how to do this either!
Any help would be great, thank you in advance.

Kind regards,
Adam

I have this:

Site    date
1   12/01/2000
1   24/02/2000
1   13/08/2001
2   14/01/2000
2   21/01/2002
3   1/01/1999
3   21/04/2000

Ultimately want this:

Site           vist1              v2                 v3
1              12/01/2000         24/02/2000         13/08/2001
2              14/01/2000         21/01/2002         na
3              01/01/1999         21/04/2000         na

But this would be good:

Site   date        visit
1      12/01/2000  1
1      24/02/2000  2
1      13/08/2001  3
2      14/01/2000  1
2      21/01/2002  2
3      01/01/1999  1
3      21/04/2000  2
  • 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-29T04:35:00+00:00Added an answer on May 29, 2026 at 4:35 am

    Basically, you are wanting to reshape your data from a long format to a wide format, with repeated observations from a Site all in a single line. The base R function reshape() was designed for just this task.

    The only (slight) complication is that you first need to add a column (which I here call obsNum) that identifies which is the first, second, third etc. observation at a Site. By setting timevar = "obsNum", you can then let reshape() know into which column you want to put each of the values of date.

    df <- read.table(text = "Site date
    1 12/01/2000
    1 24/02/2000
    1 13/08/2001
    2 14/01/2000
    2 21/01/2002
    3 1/01/1999
    3 21/04/2000", header=T, stringsAsFactors=FALSE)
    
    df$obsNum <- unlist(sapply(rle(df$Site)$lengths, seq))
    reshape(df, idvar="Site", timevar="obsNum", direction="wide")
    
    #   Site     date.1     date.2     date.3
    # 1    1 12/01/2000 24/02/2000 13/08/2001
    # 4    2 14/01/2000 21/01/2002       <NA>
    # 6    3  1/01/1999 21/04/2000       <NA>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I want to construct a data frame in an Rcpp function, but when I
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.