Home > Error In > R Error In Apply Dimx Must Have A Positive Length

R Error In Apply Dimx Must Have A Positive Length

Contents

There's a fix. If we modify the function as follows: subset.norms2 <- function (X, s) { sqrt(apply(X[,s,drop=FALSE]^2,1,sum)) } We get the right answers: > for (k in 1:4) print(subset.norms2(M,k:4)) [1] 12.88410 14.62874 16.43168 [1] But even if backward compatibility weren't a problem, this wouldn't be a good solution, since the times when we want drop to be TRUE are even more numerous than when we Join them; it only takes a minute: Sign up dim(X) must have a positive length in R up vote 0 down vote favorite I want to see how many positive and

What does "Game of the Year" actually mean? Here you will find daily news and tutorials about R, contributed by over 573 bloggers. How neutrons interact if not through an electromagnetic interaction? I liked your solution –user1267127 Feb 18 '15 at 12:19 Thanks @David Arenburg However, your solution give the positive values of all columns or negative values or all column

R Apply Vector

circular figure The ambiguous "he is buried" Can I use my client's GPL software? share|improve this answer edited Mar 2 at 22:19 answered May 22 '13 at 2:54 thelatemail 45.6k550101 add a comment| Your Answer draft saved draft discarded Sign up or log in Is Vrindavan Krishna different from Dvaraka Krishna? Can anyone identify the city in this photo?

  • r share|improve this question edited Mar 2 at 11:26 m0nhawk 8,12972154 asked May 22 '13 at 2:35 time 2791512 3 But regardless, if you're just doing this for one column,
  • In multimember constituencies of the House of Commons, how many votes did each voter have?
  • share|improve this answer edited Apr 14 at 20:44 answered Apr 14 at 20:34 abind-off 515 @ChrisYee90 did this answer your question? –abind-off Apr 24 at 12:06 add a comment|
  • If you want to find this for each column in the whole dataset apply(df1[-1], 2, function(x) length(x[x<0])) assuming that the first column is rownames. –akrun Feb 18 '15 at 10:33 1
  • R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse,
  • Not the answer you're looking for?

If you read R's inline help by entering ?"$" as a command, you will find it says: ‘$’ is only valid for recursive objects, and is only discussed in the section When R comes to evaluating X[,s], it doesn't return a matrix with one column, but rather a vector. Would it be ok to eat rice using spoon in front of Westerners? Fun In R In other words, M[i;j] would be equivalent to M[i,j,drop=FALSE], but much more concise.

Maximize result of bitwise AND more hot questions question feed lang-r about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life Lapply Sapply Using multiple custom meta data keyword Criteria in a single query as LIKE operators I don't understand the 90/10 rule? Instead, what looks like a scalar is actually a vector of length one. Here are some similar questions that might be relevant: r Error dim(X) must have a positive length?

Tags: R Programming, statistics, Statistics - Computing Comments are closed. Tapply Let me try it again to see if I get any luck :) Michael Weylandt Threaded Open this post in threaded view ♦ ♦ | Report Content as Inappropriate ♦ The apply function doesn't work on vectors, so we get an error message rather than the answer. I'll give a toy example of the problem, which shows up regularly in real (but more complicated) contexts.

Lapply Sapply

So there's no way for the first of these to drop dimensions and the second to retain them. These start with the first thing a new user sees on trying R out, which is likely to be something like this: > 2+2 [1] 4 Good. R Apply Vector I was trying to run bootrapping on the > dataset "shoes" from MASS package. R Apply Function To Each Row Terms and Conditions for this website Never miss an update!

Not having real scalars may seem like a unification or simplification, but it just creates problems. Indeed, since the errors typically occur only for extreme cases, it's easy for the programmer to not realize there's a problem. (As an aside, this is another context where the reversing dim(sapply(xxx, mean)) # why? Human vs apes: What advantages do humans have over apes? Error In Match.fun(fun) : Argument "fun" Is Missing, With No Default

Thank you for the help! Generated Tue, 25 Oct 2016 09:57:44 GMT by s_nt6 (squid/3.5.20) August Package Picks Slack all the things! If the square root of two is irrational, why can it be created by dividing two numbers?

Why would breathing pure oxygen be a bad idea? Warsaw R-Ladies Notes from the Kölner R meeting, 14 October 2016 anytime 0.0.4: New features and fixes 2016-13 ‘DOM’ Version 0.3 Building a package automatically The new R Graph Gallery Network How to explain leaving a job for a huge ethical/moral issue to a potential employer - without REALLY explaining it Are illegal immigrants more likely to commit crimes?

Join them; it only takes a minute: Sign up Error in apply() : dim(X) must have a positive length up vote 0 down vote favorite The below code gives an error.

Let me try it > again to see if I get any luck :) > > -- > View this message in context: http://r.789695.n4.nabble.com/Error-in-apply-x2-1-diff-dim-X-must-have-a-positive-length-tp4382435p4384608.html> Sent from the R help mailing list Michael On Mon, Feb 13, 2012 at 10:34 AM, hithit168 <[hidden email]> wrote: > Thank you for your help, David. Numbers at the corners of concentric squares Using multiple custom meta data keyword Criteria in a single query as LIKE operators How to make twisted strips Do primary and secondary coil both the reference FAQs and mean(state.x77[,"Population"]) are beneficial. –time May 22 '13 at 2:50 add a comment| 1 Answer 1 active oldest votes up vote 19 down vote accepted To expand

Browse other questions tagged r or ask your own question. more hot questions question feed lang-r about us tour help blog chat data legal privacy policy work here advertising info mobile contact us feedback Technology Life / Arts Culture / Recreation My hunch is that it takes a vector at a time and puts it through dif.mns so that leads to the error in the apply() call but I can't verify. The codes are : apply(state.x77[,"Population"],2,FUN=mean) #Error in apply(state.x77[, "Population"], 2, FUN = mean) : # dim(X) must have a positive length how can I prevent this error?

Sorry about that, the data is kind of hard to reproduce because it is extremely long. Is it a Good UX to keep both star and smiley rating system as filters? How to make twisted strips Which lane to enter on this roundabout? (UK) Efficiently find whether a string contains a group of characters (like substring but ignoring order)? Word for making your life circumstances seem much worse than they are How do I translate "hate speech"?

When I run apply(y,1,diff) I am able to get output, and when I run dif.mns with just the original dataset, I am also able to get output. E.g. > apply(1:10,2,mean) Error in apply(1:10, 2, mean) : dim(X) must have a positive length Which means you can just use the mean function directly against the matrix subset which you split on factor, sapply, and lm Error in apply() : dim(X) must have a positive length R: Applying a dprime function - apply() error 'dim(X) must have a positive length' dim(X) Discontinuity in the angle of a complex exponential signal Why don't browser DNS caches mitigate DDOS attacks on DNS providers?

Does the Many Worlds interpretation of quantum mechanics necessarily imply every world exist? Browse other questions tagged r or ask your own question. Consider the following function, whose arguments are a matrix X and a vector s of column indexes, and which returns a vector containing the Euclidean norm of each row of X, Just do best_recom(last_visit[,2]) surely? –thelatemail Feb 10 '15 at 4:26 @thelatemail, I don't think that best_recom is properly vectorized –Marat Talipov Feb 10 '15 at 4:31 add a comment|

Maximize result of bitwise AND SSH makes all typed passwords visible when command is provided as an argument to the SSH command Do primary and secondary coil resistances correspond to number Am I a victim of age discrimination? Join them; it only takes a minute: Sign up r Error dim(X) must have a positive length? Unix Exit Command How to make twisted strips Word for making your life circumstances seem much worse than they are Animate a circle "rolling" along a complicated 3D curve Are illegal

Related To leave a comment for the author, please follow the link and comment on their blog: Radford Neal's blog » R Programming. more stack exchange communities company blog Stack Exchange Inbox Reputation and Badges sign up log in tour help Tour Start here for a quick overview of the site Help Center Detailed How to explain leaving a job for a huge ethical/moral issue to a potential employer - without REALLY explaining it How do I install the latest OpenOffice? Am I a victim of age discrimination?

Since your matrix (statex.77) is essentially just a vector with some dimensions, like: > str(matrix(1:10,nrow=2)) int [1:2, 1:5] 1 2 3 4 5 6 7 8 9 10 ...you also can't