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 question.(5)

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

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/How can I handle - attempt to set 'colnames' on an object with less than two dimensions?
Next
Answered
Javier Evans
  • 6
Javier Evans
Asked: May 18, 20222022-05-18T18:32:17+00:00 2022-05-18T18:32:17+00:00In: r

How can I handle – attempt to set ‘colnames’ on an object with less than two dimensions?

  • 6

. Advertisement .

..3..

. Advertisement .

..4..

I get the error message:

Error in `colnames<-`(`*tmp*`, value = c("SPY.Open", "SPY.High", "SPY.Low", : 
  attempt to set 'colnames' on an object with less than two dimensions # creating the column names

Has anyone ever faced this problem? How to troubleshoot the “attempt to set ‘colnames’ on an object with less than two dimensions”. The problem appears when I try to operate the following program:

# rm(list = ls()) # generally considered as bad manner in an MWE
 require(quantmod)
 options(scipen=999)
 spy <- getSymbols(("SPY") , src = 'yahoo', from = '2016-01-01', auto.assign = T)
 spy<-cbind(SPY)
 tail(SPY)
  SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
 2016-01-14 189.55 193.26 187.66 191.93 240795600 191.93
 2016-01-15 186.77 188.76 185.52 187.81 324846400 187.81
 2016-01-19 189.96 190.11 186.20 188.06 190196000 188.06
 2016-01-20 185.03 187.50 181.02 185.65 280016900 185.65
 2016-01-21 186.21 188.87 184.64 186.69 189174000 186.69
 2016-01-22 189.78 190.76 188.88 190.52 163849600 190.52
q <- c("2016-01-25",100,200,200,200,200,200) # creating the data
 colnames(q) <- colnames(SPY) # creating column names as in SPY
xts
  • 1 1 Answer
  • 600 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-06-15T15:34:55+00:00Added an answer on June 15, 2022 at 3:34 pm

    The cause:

    This error occurs because you are trying to set ‘colnames’ on an object which have more than two dimensions.

    Solution:

    Perhaps following is what you expect:

    q <- data.frame(100,200,200,200,200,200)
    colnames(q) <- colnames(SPY)
    q <- xts(q, as.Date("2016-01-26"))
    # SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
    # 2016-01-26 100 200 200 200 200 200
    
    class(SPY)
    # [1] "xts" "zoo"
    class(q)
    # [1] "xts" "zoo"
    
    tail(rbind(SPY, q))
    # SPY.Open SPY.High SPY.Low SPY.Close SPY.Volume SPY.Adjusted
    # 2016-01-19 189.96 190.11 186.20 188.06 190196000 188.06
    # 2016-01-20 185.03 187.50 181.02 185.65 280016900 185.65
    # 2016-01-21 186.21 188.87 184.64 186.69 189174000 186.69
    # 2016-01-22 189.78 190.76 188.88 190.52 163849600 190.52
    # 2016-01-25 189.92 190.15 187.41 187.64 122676200 187.64
    # 2016-01-26 100.00 200.00 200.00 200.00 200 200.00
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

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.