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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:49:33+00:00 2026-06-17T09:49:33+00:00

Working through an R tutorial that I’m having a hard time understanding. Directory is

  • 0

Working through an R tutorial that I’m having a hard time understanding.

Directory is a folder with numerous csv files. The function takes as id either one of more of the files and returns the number of records in each.

My function:

complete <- function(directory,id = 1:332) {

   csvfiles <- sprintf("/Users/myname/Desktop/%s/%03d.csv", directory, id)

   nrows <- sapply( csvfiles, function(f) nrow(read.csv(f)))
   data.frame(ID=sprintf('%03d', id), 
              countrows=sapply(csvfiles,function(x) length(count.fields(x))),
             row.names=id
           )
       }

Then complete(“specdata”, 100:105)
Returns

    ID countrows
100 100      1097
101 101       731
102 102      1462
103 103      3653
104 104      2558
105 105      2192

What must I do so that the left most column is a sequence starting 1? So that, for example, the first record would be 1 100 & 1092, the second record 2 101 & 731

  • 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-17T09:49:35+00:00Added an answer on June 17, 2026 at 9:49 am

    The first apparent column is just the names of the rows (look at e.g. ncol(specdata)). You can rename rows as follows:

    row.names(specdata) <- 1:nrow(specdata)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working through a tutorial and am having a tough time on syntax. I
I am having no luck getting NLog to work. Working through the tutorial ,
I'm working through a tutorial that uses Apache CXF 2.6.2 to create a RESTful
I installed Django, and started working through the tutorial. It told me that I
I'm working through the Django 1.4 tutorial , and I notice that in the
Hi im working through the Creating a store locator tutorial on google that can
I was working through a tutorial at http://fszlin.blogspot.com/2010/05/comsuming-wcf-services-with-android.html and am having a problem. The
I'm working through the Django tutorial after having installed the development source of Django
I'm working through Michael Hartl's Ruby on Rails tutorial on http://ruby.railstutorial.org . I'm having
Im working through a weather app tutorial. I am having trouble getting the reverse

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.