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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:05:14+00:00 2026-05-29T06:05:14+00:00

I have a single vector of flow data (29 data) and a 3D matrix

  • 0

I have a single vector of flow data (29 data) and a 3D matrix data(360*180*29)

i want to find the correlation between single vector and 3D vector. The correlation matrix will have a size of 360*180.

> str(ScottsCk_flow_1981_2010_JJA)
 num [1:29] 0.151 0.644 0.996 0.658 1.702 ...
> str(ssta_winter)
 num [1:360, 1:180, 1:29] NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN ...
> summary(ssta_winter)
    Min.  1st Qu.   Median     Mean  3rd Qu.     Max.     NA's 
    -2.8     -0.2      0.1      0.2      0.6      6.0 596849.0 

This above is the structure of the vector and 3D matrix. 3D matrix has many values as Null.

> for (i in 1:360) {
+   for(j in 1:180){
+       cor_ScottsCk_SF_SST_JJA[i,j] = cor(ScottsCk_flow_1981_2010_JJA,ssta_winter[i,j,]) 
+    }
+ }
There were 50 or more warnings (use warnings() to see the first 50)

This part of code above is the code to find correlation. But it gives waring as

> warnings()
Warning messages:
1: In cor(ScottsCk_flow_1981_2010_JJA, ssta_winter[i, j,  ... :
  the standard deviation is zero
2: In cor(ScottsCk_flow_1981_2010_JJA, ssta_winter[i, j,  ... :
  the standard deviation is zero
3: In cor(ScottsCk_flow_1981_2010_JJA, ssta_winter[i, j,  ... :
  the standard deviation is zero
4: In cor(ScottsCk_flow_1981_2010_JJA, ssta_winter[i, j,  ... :
  the standard deviation is zero
5: In cor(ScottsCk_flow_1981_2010_JJA, ssta_winter[i, j,  ... :
  the standard deviation is zero

also, the result of the correlation matrix is all NULL. how did this happen?

> str(cor_ScottsCk_SF_SST_JJA)
 num [1:360, 1:180] NA NA NA NA NA NA NA NA NA NA ...

I have used exact same code bfr with 350 flow vector and 360*180*350 matrix.
This code works perfectly.

  • 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-29T06:05:15+00:00Added an answer on May 29, 2026 at 6:05 am

    A few thoughts.

    First, by using apply(), you can replace that nested loop with something like this:

    cor_ScottsCk_SF_SST_JJA <- 
        apply(ssta_winter, MARGIN = 1:2, FUN = cor, ScottsCk_flow_1981_2010_JJA)
    

    Second, it appears that >31% (596849/(360*180*29)) of the points in ssta_winter are NaN or (possibly) NA_real_. Given the return value of a correlation calculated on vectors that contain even a single NaN,

    cor(c(1:3, NaN), c(1:4))
    # [1] NA
    

    isn’t it likely that all those NaNs are causing cor_ScottsCk_SF_SST_JJA to be filled with NAs?

    Third, as the warning messages plainly tell you, some of the vectors you are passing to cor() have zero variance. They have nothing to do with the NaNs: as the following shows, R doesn’t complain about standard deviations of 0 when NaN are involved. (Quite sensibly too, since you can’t calculate standard deviations for undefined numbers):

    cor(c(NaN, NaN, NaN, NaN), c(1,1,1,1))
    # [1] NA
    
    cor(c(1,1,1,1), c(1,2,3,4))
    # [1] NA
    # Warning message:
    # In cor(c(1, 1, 1, 1), c(1, 2, 3, 4)) : the standard deviation is zero
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a single Rails 2.2.2 app that I want to 'share' with multiple
I have a std::vector<std::string> which would contain numbers and characters (single char). I would
I have a function something like: MyClass1 mc1, mc0; //Single Object MyClass2 mc2; //vector
I have a vector containing large number of elements. Now I want to write
I have two vectors of floats and i want them to become one vector
I have a very long vector of single characters i.e. somechars<-c(A,B,C,A...) (length is somewhere
I have a number of vector containers of varying size each containing doubles. I
i am now having a single date vector A (362 rows) and i have
I have the following code (compiler: MSVC++ 10): std::vector<float> data; data.push_back(1.0f); data.push_back(1.0f); data.push_back(2.0f); //
I have an single threaded, embedded application that allocates and deallocates lots and lots

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.