"missing value where TRUE/FALSE needed" error messages all over the place

1,195 views
Skip to first unread message

Stuart Luppescu

unread,
May 6, 2015, 7:03:55 PM5/6/15
to manip...@googlegroups.com
Hi all, I seem to be getting these messages a lot where I don't expect them. First I was just calculating a mean of columns for each row, something like:

 va <- final_summative %>%
+     select(tid, va_read, va_math, iva_orig_score, va_mathse, va_readse) %>%
+     group_by(tid) %>%
+      mutate(my_iva=mean(va_read, va_math, na.rm=TRUE))
Error in if (trim > 0 && n) { : missing value where TRUE/FALSE needed

(Oh, did I need to enclose the arguments to mean() in c()?)
But then I did this and it worked OK:

> va <- final_summative %>%
+     select(tid, va_read, va_math, iva_orig_score, va_mathse, va_readse, va_math_n, va_read_n) %>%
+         filter(!is.na(tid)) %>%
+         group_by(tid) %>%
+             mutate(my_va_se=weighted.mean(x=c(va_read, va_math), w=c(va_read_n, va_math_n), na.rm=TRUE))

But then when I tried to look at a few cases to check that it was doing what I wanted to do, I got the same error:

> va[1:10, 5:10]
Error in if (any(names2(x) == "")) { : 
  missing value where TRUE/FALSE needed

This does not make sense to me. Here is my session info:
R version 3.1.3 (2015-03-09)
Platform: x86_64-redhat-linux-gnu (64-bit)
Running under: Red Hat Enterprise Linux Server release 6.6 (Santiago)

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] reshape2_1.4.1   scales_0.2.4     ggplot2_1.0.1    gmodels_2.15.4.1
[5] dplyr_0.4.1     

loaded via a namespace (and not attached):
 [1] assertthat_0.1   colorspace_1.2-6 compiler_3.1.3   DBI_0.3.1       
 [5] digest_0.6.8     gdata_2.16.1     grid_3.1.3       gtable_0.1.2    
 [9] gtools_3.4.2     labeling_0.3     lazyeval_0.1.10  magrittr_1.5    
[13] MASS_7.3-40      munsell_0.4.2    parallel_3.1.3   plyr_1.8.2      
[17] proto_0.3-10     Rcpp_0.11.6      stringi_0.4-1    stringr_1.0.0   
[21] tools_3.1.3     

TIA.

--
Stuart Luppescu -- pixbuf .at. gmail.com
What's another word for euphemism?
  -- Karen Ellis: http://planetkaren.girl-wonder.org/index.php?strip_id=608

Brandon Hurr

unread,
May 7, 2015, 12:48:03 PM5/7/15
to Stuart Luppescu, manipulatr
Stuart, 

Could you provide a small dataset in dput() format to go with your code? 

Looks like it's mean() expecting TRUE/FALSE as it's second argument and you're giving it another column.

I'm really unsure what you're wanting from va[1:10, 5:10].

B

--
You received this message because you are subscribed to the Google Groups "manipulatr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to manipulatr+...@googlegroups.com.
To post to this group, send email to manip...@googlegroups.com.
Visit this group at http://groups.google.com/group/manipulatr.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages