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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T23:39:55+00:00 2026-06-03T23:39:55+00:00

I have an R related question which is to do with having to read

  • 0

I have an R related question which is to do with having to read in many files and process these files.
Each file is for measurements of ozone made at a different time at a different station. The data is in a table format and I can read the data in using:

files <- list.files()
data  <- lapply(files, read.table, skip=19)

This gives me a data frame for all the files which I would like to now process. For example the files are named:

> head(files)
 [1] "fiji_19980105.dat" "fiji_19980112.dat" "fiji_19980119.dat"
 [4] "fiji_19980130.dat" "fiji_19980206.dat" "fiji_19980213.dat"

Where “fiji” is the name of the station and the date is YMD format. I would like to average the data frame to get monthly averages for this station (I will only need to work on one station at a time, so really I just want to average the data frame called data to produce 12 sets of average data).

I imagine I can do this using some ?apply function, but I’m really lost on how to do this. Any suggestions on a solution are really appreciated!

As an example of the result of adding the dates to the data frame here we have:

> head(dat)
V1     V2    V3   V4 V5   V6    V7   V8   V9  V10       Date
1 9000 1007.7 0.006 29.6 74 0.59 0.006 9000 9000 9000 1998-01-05
2 9000 1005.2 0.028 29.3 75 0.62 0.006 9000 9000 9000 1998-01-05
3 9000 1001.6 0.060 28.5 78 0.63 0.006 9000 9000 9000 1998-01-05

 > str(dat)
'data.frame':   153994 obs. of  11 variables:
 $ V1  : int  9000 9000 9000 9000 9000 9000 9000 9000 9000 9000 ...
 $ V2  : num  1008 1005 1002 997 993 ...
 $ V3  : num  0.006 0.028 0.06 0.104 0.14 0.169 0.198 0.238 0.271 0.301 ...
 $ V4  : num  29.6 29.3 28.5 27.9 27.6 27.2 27 26.6 26.2 26 ...
 $ V5  : int  74 75 78 79 80 81 82 84 85 85 ...
 $ V6  : num  0.59 0.62 0.63 0.68 0.69 0.7 0.72 0.74 0.75 0.76 ...
 $ V7  : num  0.006 0.006 0.006 0.007 0.007 0.007 0.007 0.008 0.008 0.008 ...
 $ V8  : num  9000 9000 9000 9000 9000 9000 9000 9000 9000 9000 ...
 $ V9  : num  9000 9000 9000 9000 9000 9000 9000 9000 9000 9000 ...
 $ V10 : num  9000 9000 9000 9000 9000 9000 9000 9000 9000 9000 ...
 $ Date: Date, format: "1998-01-05" "1998-01-05" ...
  • 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-03T23:39:57+00:00Added an answer on June 3, 2026 at 11:39 pm

    With your list of files, get Dates:

    datetimes = as.Date(files, "fiji_%Y%m%d")
    

    See ?strptime for details about the format templates, essentially you can include whatever other values as literal filler, and ignore any trailing characters that don’t matter.

    The rest requires that you give more information about what is in each data.frame, so give us more information about the data in those.

    It would be best to create one large data.frame with these date stamps added to each row, and then go from there.

    To get that something like this would work (imagine it’s called ‘dat’ rather than ‘data’):

    dat = lapply(files, read.table, skip=19)
    
    for (i in 1:length(files)) {
        dat[[i]]$Date = rep(datetimes[i], nrow(dat[[i]])
    
    }
    
    dat = do.call("rbind", dat)
    

    Then you can use format(dat$Date, "%m") to get a value for each date that only includes the month, and tapply across that with a summary function (e.g. mean). There would be less classical plyr versions of this that will no doubt come up soon. 🙂

    It’s probably not a good idea to call read.table with lapply, so I would change that as well so you can put in basic checks for each I/O and the merging of the data.frames.

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

Sidebar

Related Questions

I have read other related question but i cant really get them to relate
I have a question related to query . I have a table in which
I have question related to what is done in SMS application is if i'm
I have seen the related question here: An object with the same key already
Hi I have a Subclipse related question. In SVN when you merge the trunk
I have a question related to this one . I don't want to do
I have a question related to this one : I'm trying to attach an
I have a question related to understanding of how python dictionaries work. I remember
I have following event class. I have a question related to the Property method
I have a modeling question related to profiles. Firstly, I have looked into using

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.