Error In Complete.casesx Y
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company error in complete.cases() : not all arguments have the same length Business Learn more about hiring developers or posting ads with us Stack Overflow Questions nnetar not all arguments have the same length Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million paired t test missing data programmers, just like you, helping each other. Join them; it only takes a minute: Sign up R - complete.cases not all arguments have the same length up vote 0 down vote favorite I have problem with R
Paired T Test R
complete.cases() funciton. I am using Electric power consumption data and I wanted to check if there are any NAs in my subset using complete.cases() function. I expect to get number of complete cases but instead I get an error saying that "not all arguments have the same legnth". I give complete.cases() only one argument that is data frame. All columns in df have the same length. Of course I can check NAs in every r t test column using sum(is.na()) funciton but I am curious why complete.cases() doesn't work. Moreover when I generated data frame with 3 columns filled by random numbers complete.cases() worked. Here is my code so that you can reproduce error: ### READING DATA # reading full file data <- read.table("household_power_consumption.txt", header=1, sep=";", na.strings="?") # changing Date and Time columns to R classes data$Time = strptime(paste(data$Date, data$Time),"%d/%m/%Y %H:%M:%OS") data$Date = as.Date(data$Date, format="%d/%m/%Y") # filtering to needed days data = subset(data, Date == '2007-02-01' | Date == '2007-02-02') # checking if there are any NAs in data dim(data) sum(complete.cases(data)) r na share|improve this question asked Apr 11 '15 at 18:09 Adrian Gasiński 34 1 Thanks for the reproducible code, but it is better if you provided a small dataset (instead of the zip file) that reproduce the error. –akrun Apr 11 '15 at 18:13 2 Convert your POSIXlt (list) column to POSIXct (vector) and it'll work: data$Time <- as.POSIXct(data$Time); sum(complete.cases(data)). See also here: stackoverflow.com/questions/27957819/… –lukeA Apr 11 '15 at 18:19 @lukeA thank you for your help. –Adrian Gasiński Apr 11 '15 at 19:49 @akrun ok, I will remember next time –Adrian Gasiński Apr 11 '15 at 19:50 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted There is some problem with comp
NA´s Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] 1. There should have been warning or error when using "_" as it is depreceated. Use "<-" instead. 2. There is an extra "]" 3. Could it be that after removing all the cases with NA, you do not have sufficient observations. Example : > j <- c(NA, 2, NA, 4, NA) http://stackoverflow.com/questions/29581304/r-complete-cases-not-all-arguments-have-the-same-length > k <- c(1, NA, 3, NA, 5) > lm(j~k,na.action=na.exclude) Error in lm.fit(x, y, offset = offset, singular.ok = singular.ok, ...) : 0 (non-NA) cases 4. I would suggest you put a 'cat(i, "before", "\n") or something similar before and after the problematic syntax to find out which values of i https://stat.ethz.ch/pipermail/r-help/2004-May/050530.html is causing the problem. On Tue, 2004-05-04 at 14:55, Christoph Scherber wrote: > actually, the situation is much more complicated. I am producing > multiple graphs within a "for" loop. For some strange reason, the > plotting routine always stops once lm(y~x) encounters more than one > missing value (I have marked the important bit with "***********"): > > par(mfrow=c(5,5)) > p_seq(3,122,2) > i_0 > k_0 > number_0 > for (i in p) { > j_foranalysis[93:174,i+1] > k_foranalysis[93:174,i] > df_data.frame(j,k) > mainlab1_substring(names(foranalysis[i]),2,8) > mainlab2_"; corr.:" > mainlab3_round(cor(j,k,na.method="available"),4) > mainlab4_"; excl.Mono:" > mainlab5_round(cor(j[j<0.9],k[j<0.9],na.method="available"),4) > mainlab_paste(mainlab1,mainlab2,mainlab3,mainlab4,mainlab5) > plot(k,j,main=mainlab,xlab="% of total biomass",ylab="% of total > cover",pch="n") > for (k in 1:length(foranalysis[93:174,i])) > number[k]_substring(plotcode[foranalysis[k,1]],1,5) > text(foranalysis[93:174,i],foranalysis[93:174,i+1],number) > ********************************** > model_lm(j~k,na.action=na.exclude]) > ********************************** > abline(model) > abline(0,1,lty=2) > } > > Does anyone have any suggestions on this? > > Best regards > Chris., > > > > > Liaw, Andy wrote: > > >By (`factory') default t
by over 573 bloggers. There are many ways to follow us - By e-mail: On Facebook: If you are an R blogger yourself you are https://www.r-bloggers.com/translating-weird-r-errors/ invited to add your own R content feed to this site (Non-English R bloggers should add themselves- here) Jobs for R-usersFinance Manager @ Seattle, U.S.Data Scientist – AnalyticsTransportation Market Research Analyst @ Arlington, U.S.Data AnalystData Scientist for Madlan @ Tel Aviv, Israel Popular Searches web scraping heatmap twitter maps time series boxplot animation shiny how to import image file to R hadoop Ggplot2 trading latex finance eclipse excel t test quantmod sql googlevis PCA knitr rstudio ggplot market research rattle regression coplot map tutorial rcmdr Recent Posts RcppAnnoy 0.0.8 R code to accompany Real-World Machine Learning (Chapter 2) R Course Finder update ggplot2 2.2.0 coming soon! All the R Ladies One Way Analysis of Variance Exercises GoodReads: Machine Learning (Part 3) Danger, Caution H2O steam is very hot!! R+H2O for marketing campaign modeling Watch: Highlights of the Microsoft not all arguments Data Science Summit A simple workflow for deep learning gcbd 0.2.6 RcppCNPy 0.2.6 Using R to detect fraud at 1 million transactions per second Introducing the eRum 2016 sponsors Other sites Jobs for R-users SAS blogs Translating Weird R Errors January 20, 2013By Slawa Rokicki (This article was first published on R for Public Health, and kindly contributed to R-bloggers) I love R. I think it's intuitive and clever and overall a great language. But I do get really annoyed sometimes at the completely ridiculous, cryptic error messages it often gives me. This post will go over some of those seemingly nonsensical errors so you don't have to go crazy trying to find the bug in your code. 1. all arguments must have the same length To start with, I just make up some quick data: prob1<-as.data.frame(cbind(c(1,2,3),c(5,4,3)))colnames(prob1)<-c("Education","Ethnicity") And now I just want to do a simple table but I get this error: What the heck. I look back at my dataset and make sure that both those variables are the same length, which they are. The problem here is that I misspelled "Education". There's a missing "a" in there and instead of telling me that I referenced a variable that doesn't exi