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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:26:23+00:00 2026-05-23T09:26:23+00:00

I have a few files with zoo objects that look like this (each file

  • 0

I have a few files with zoo objects that look like this (each file starts and ends at different dates):

           code pp  
1942-06-01 4016  0  
1942-06-02 4016  NA  
1942-06-03 4016  0  
1942-06-04 4016  0  
1942-06-05 NA    0  
1942-06-06 NA    0

I want to do a correlation matrix between the pp of all files for the months of September, October and November (showing the codes so I can identify who is who). I cannot use the list.files function (code kindly supplied by Joran in Correlation matrix between different files) because of the NAs in the code column. So I came up with the folowing code:

files <- list.files(pattern=".csv")
xx<-read.zoo(files[1],sep=",", header=TRUE,index.column=1)  
name<- as.name(xx$code[[1]])  
colnames(xx) <- c("code", name)  
x<-xx[months(time(xx), TRUE) %in% c("Sep", "Oct", "Nov")]  
yy<-read.zoo(files[2],sep=",", header=TRUE,index.column=1)  
name<- as.name(yy$code[1])  
colnames(yy) <- c("code", name)  
y<-yy[months(time(yy), TRUE) %in% c("Sep", "Oct", "Nov")]  
CET<-merge(x, y, all = TRUE, fill = NA, check.names=FALSE)  
for (i in 3:length(files))  
{
  z<-read.zoo(files[i],sep=",", header=TRUE,index.column=1)  
  name<- as.name(z$code[1])  
  colnames(z) <- c("code", name)  
  CET<-merge(CET, z, all = TRUE, fill = NA, check.names=FALSE)  
}  
a<-1:(dim(CET)[2])  
even <- a[ a%%2 == 0 ]    
# saves the precipitation column (even numbers) and discards the code ones
dat<-CET[,even]
c.mat<-cor(dat,use="pairwise.complete.obs" )

But something is wrong: in the correlation matrix some of the column/rows names have an extra “.z” or “.CET” and, most importantly the correlation coefficients are not correct! I cannot find the problem so any help finding the problem or proposing a simpler code to do this will be very 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-23T09:26:23+00:00Added an answer on May 23, 2026 at 9:26 am

    I don’t know why, but if instead of extracting the month I want from each file and then merge them in 1 file, I merge the files and only then extract the months that I want the values of the correlations are correct! What I mean is:


    files <- list.files(pattern=".csv")
    x<-read.zoo(files[1],sep=",", header=TRUE,index.column=1)
    y<-read.zoo(files[2],sep=",", header=TRUE,index.column=1)
    CET<-merge(x, y, all = TRUE, fill = NA, check.names=FALSE)
    for (i in 3:length(files))
    {
    z<-read.zoo(files[i],sep=",", header=TRUE,index.column=1)
    CET<-merge(CET, z, all = TRUE, fill = NA, check.names=FALSE)
    }
    a<-1:(dim(CET)[2])
    even <- a[ a%%2 == 0 ]
    dat<-CET[,even]
    dat.aut<-dat[months(time(dat), TRUE) %in% c("Sep", "Oct", "Nov")]
    c.mat<-cor(dat.aut,use="pairwise.complete.obs" )

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

Sidebar

Related Questions

I have a few HTML files that I'd like to include via tags in
I have a few different OBJ files that I am able to parse and
I have a few files like this- *.sss and *_passive.sss If I have a
I have a few things in various different files that get called from different
In almost all of my projects I have few files that are project wide
I have a few files that were part of an update that were mistakenly
I have a few text files and I'd like to count how many times
I have a few log files like these: /var/log/pureftpd.log /var/log/pureftpd.log-20100328 /var/log/pureftpd.log-20100322 Is it possible
I have a few directories and sub-directories containing files with no file extension. I
I have a WiX project that installs a few EXE files. One is the

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.