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/The dim(x) must have a positive length error: what should you do?
Next
Answered
Lucas Besnard
  • 20
Lucas Besnard
Asked: May 17, 20222022-05-17T12:45:13+00:00 2022-05-17T12:45:13+00:00In: r

The dim(x) must have a positive length error: what should you do?

  • 20

. Advertisement .

..3..

. Advertisement .

..4..

I am new to r and searching the “dim(x) must have a positive length” to understand it better. It seems it doesn’t work as expected when I used some suggestions before. Here is the command line I use:

best_recom <- function(x,n=1) {
  y <- result2[x,order(-result2[x,])[n]]
  inds = which(result2[x,] == y, arr.ind=TRUE)
  recom <- names(inds[1])
  return(recom)
 }
apply(last_visit[,2], 1, best_recom)
dim(X) must have a positive length
apply(as.matrix(last_visit)[,2],1,recomenda_n_melhor)
X1.0 X1.1 X2.1 X3.1
 X1.0 0.0000000 0.5000000 0.3872983 0.3162278
 X1.1 0.5000000 0.0000000 0.2581989 0.0000000
 X2.1 0.3872983 0.2581989 0.0000000 0.0000000
 X3.1 0.3162278 0.0000000 0.0000000 0.0000000
customer cat
 1 1 X5.1
 2 2 X6.1
 3 3 X1.1
 4 4 X2.1

The error I’m getting is below:

dim(X) must have a positive length

Please give me the solution to this issue.

dim(x)
  • 1 1 Answer
  • 60 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    dttutoria Expert
    2022-06-03T12:05:29+00:00Added an answer on June 3, 2022 at 12:05 pm

    The cause: The error appears because R coerces last_visit[,2] to a dimensionless vector, whereas apply needs to have some dimensions of the object.

    Solution: You can stop the compulsion by adding drop=F to the command:

    apply(last_visit[,2,drop=F], 1, best_recom)

    Or on the vector, you use lapply or sapply like this:

    lapply(last_visit[,2], best_recom)
    • 23
    • 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.