search for: addna

Displaying 20 results from an estimated 21 matches for "addna".

Did you mean: adda
2016 Aug 17
1
table(exclude = NULL) always includes NA
...ow (in R-devel, after my changes) triggers in > cases it did not previously, notably in > table(1:3, exclude = 1) > which now does set 'useNA = "ifany"' and so gives the same silly > result as the one above. > The reason for this bug is that addNA(..) is called (in all R > versions mentioned) in this case, but it should not. > I'm currently testing yet another amendment.. which was not sufficient... so I had to do *much* more work. The result is code which functions -- I hope -- uniformly better than the current code, b...
2016 Aug 15
1
table(exclude = NULL) always includes NA
...1 1 1 > and that bug now (in R-devel, after my changes) triggers in cases it did not previously, notably in table(1:3, exclude = 1) which now does set 'useNA = "ifany"' and so gives the same silly result as the one above. The reason for this bug is that addNA(..) is called (in all R versions mentioned) in this case, but it should not. I'm currently testing yet another amendment.. Martin
2016 Sep 10
1
table(exclude = NULL) always includes NA
...ow (in R-devel, after my changes) triggers in > cases it did not previously, notably in > table(1:3, exclude = 1) > which now does set 'useNA = "ifany"' and so gives the same silly > result as the one above. > The reason for this bug is that addNA(..) is called (in all R > versions mentioned) in this case, but it should not. > I'm currently testing yet another amendment.. which was not sufficient... so I had to do *much* more work. The result is code which functions -- I hope -- uniformly better than the current code, b...
2016 May 23
2
data frame method for as.table()
Hello, Currently it's possible to convert an object of class table to a data frame with as.data.frame.table(), but there's no ready-made function, AFAIK, to do the reverse operation, i.e. conversion of a data frame to a table. Do you think it would be a good idea to add a data.frame method to as.table(), to allow such conversions? The idea is that if `x' is a table and `y <-
2012 Dec 13
0
Suggestion of change to reduce overhead of 'table'
...? ? ? ???if (any(llexcl) || >? ? ? ? ? ? ? ? ? ? ? ???(useNA == "no" && any(is.na(ll)))) >? ? ? ? ? ? ? ? ? ? ? ? ? ???factor(a, levels = ll[!llexcl], 86a90,91 >? ? ? ? ? ? ? ? ? ? ? ???else >? ? ? ? ? ? ? ? ? ? ? ? ? ???a Function 'table' calls function 'addNA' in some cases. I suggest to change 'addNA', too. This is diff against https://svn.r-project.org/R/trunk/src/library/base/R/factor.R. 336d335 <? ???if (ifany & !any(is.na(x))) return(x) 338c337,339 <? ???if (!any(is.na(ll))) ll <- c(ll, NA) --- >? ???hasNAlev <- any(...
2016 May 23
0
data frame method for as.table()
...t; as.table(yy) > foo > a b <NA> > 2 2 1 >> > > Any thoughts? Hi, I have not tried an exhaustive set of examples, but I believe that ?xtabs will get you most of the way there, with the exception of NA handling, which would require either nuanced use of ?addNA or preprocessing factors in the input data frame to possibly add NA as a factor level where needed. BTW, from ?as.data.frame.table, see the reference there to xtabs() at the end: "The as.data.frame method for objects inheriting from class "table" can be used to convert the array-ba...
2017 Jan 19
2
xtabs(), factors and NAs
...data=test) x a? 1? > test <- data.frame(x=factor(c("a",NA))) > xtabs(~ x, exclude=NULL, na.action=na.pass, data=test) x a? 1? Even if it's documented, this inconsistency is annoying. When checking data, it is often useful to print all NA values temporarily, without calling addNA() individually on all crossed variables. Would it make sense to add a new argument similar to table()'s useNA which would behave the same for all input vector types? Regards 1: https://bugs.r-project.org/bugzilla/show_bug.cgi?id=14630
2011 Apr 20
3
Make as.factor an S3 generic?
...rdered} \alias{as.factor} +\alias{as.factor.default} \alias{as.ordered} +\alias{as.ordered.default} \alias{is.na<-.factor} \alias{Math.factor} \alias{Ops.factor} @@ -40,8 +42,8 @@ is.factor(x) is.ordered(x) -as.factor(x) -as.ordered(x) +as.factor(x, \dots) +as.ordered(x, \dots) addNA(x, ifany=FALSE) } -- Computational Biology Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N. PO Box 19024 Seattle, WA 98109 Location: M1-B861 Telephone: 206 667-2793
2017 Jun 06
2
integrating 2 lists and a data frame in R
...<-as.character(C[,1]) > C[,2]<-as.character(C[,2]) > for(row in 1:dim(C)[1]) MN[C[row,1],C[row,2]]<-C[row,3] `xtabs` offers another route: C$m <- factor(C$m, levels=M$M) C$n <- factor(C$n, levels=N$N) Option 1: Zeroes in the empty positions: > (X <- xtabs(I ~ m+n , C, addNA=TRUE)) n m n1 n2 n3 n4 m1 100 300 0 0 m2 0 0 0 0 m3 0 0 400 0 m4 0 0 0 0 m5 0 0 0 0 Option 2: Sparase matrix > (X <- xtabs(I ~ m+n , C, sparse=TRUE)) 5 x 4 sparse Matrix of class "dgCMatrix" n m n1 n2 n3 n4 m1 100 3...
2017 Jan 20
0
xtabs(), factors and NAs
...actor(c("a",NA))) > > xtabs(~ x, exclude=NULL, > na.action=na.pass, data=test) > x > a? > 1? > > > Even if it's documented, this inconsistency is annoying. When checking > data, it is often useful to print all NA values temporarily, without > calling addNA() individually on all crossed variables. {Note this is not (just) about print()ing; the issue is about the resulting *object*.} > > Would it make sense to add a new argument similar to table()'s useNA > which would behave the same for all input vector types? You have to be awar...
2018 Aug 21
1
bug report: inaccurate error message for stats::chisq.test
Hi, `stats::chisq.test` checks that x and y each have at least 2 levels AFTER filtering on complete cases. It makes sense but the error message is misleading : ?'x' and 'y' must have at least 2 levels? Here?s how to reproduce the issue : x <- structure(c(1L, 1L, 1L, 2L, 1L, 2L), .Label = c("0001", "0003"), class = "factor") y <-
2017 Jun 06
0
integrating 2 lists and a data frame in R
....character(C[,2]) > > for(row in 1:dim(C)[1]) MN[C[row,1],C[row,2]]<-C[row,3] > > `xtabs` offers another route: > > C$m <- factor(C$m, levels=M$M) > C$n <- factor(C$n, levels=N$N) > > Option 1: Zeroes in the empty positions: > > (X <- xtabs(I ~ m+n , C, addNA=TRUE)) > n > m n1 n2 n3 n4 > m1 100 300 0 0 > m2 0 0 0 0 > m3 0 0 400 0 > m4 0 0 0 0 > m5 0 0 0 0 > > Option 2: Sparase matrix > > (X <- xtabs(I ~ m+n , C, sparse=TRUE)) > 5 x 4 sparse Matrix of class &quo...
2017 Jun 06
1
integrating 2 lists and a data frame in R
...row in 1:dim(C)[1]) MN[C[row,1],C[row,2]]<-C[row,3] >> >> `xtabs` offers another route: >> >> C$m <- factor(C$m, levels=M$M) >> C$n <- factor(C$n, levels=N$N) >> >> Option 1: Zeroes in the empty positions: >> > (X <- xtabs(I ~ m+n , C, addNA=TRUE)) >> n >> m n1 n2 n3 n4 >> m1 100 300 0 0 >> m2 0 0 0 0 >> m3 0 0 400 0 >> m4 0 0 0 0 >> m5 0 0 0 0 >> >> Option 2: Sparase matrix >> > (X <- xtabs(I ~ m+n , C, sparse=TRUE)...
2015 Feb 09
3
xtabs and NA
Hi I haven't found a way to produce a tabulation from factor data with NA values using xtabs. Please find a minimal example below, it's also on R-pubs [1]. Tested with R 3.1.2 and R-devel r67720. It doesn't seem to be documented explicitly that it's not supported. From reading the code [2] it looks like the relevant call to table() doesn't set the "useNA"
2017 Aug 10
3
Creating New Variable Using Ifelse
...ge studies that was NOT a WBL experience elsq2wbl$NONWBLRELJOB <- ifelse(elsq2wbl$PSWBL=="No" & elsq2wbl$EVERRELJOB=="Yes",1,0) #Cross tab to check counts of two variables that new variable is based upon xtabs(~PSWBL+EVERRELJOB,subset(elsq2wbl,BYSCTRL==1&G10COHRT==1),addNA=TRUE) #Checking count of newly created variable Q2sub <- subset(elsq2wbl,BYSCTRL==1&G10COHRT==1) library(plyr) count(Q2sub,'NONWBLRELJOB') #The new variable has the correct count of "1", but 88 cases too many for "0" #The cross tab shows 20 and 68 NA cases that...
2011 Mar 19
2
persuade tabulate function to count NAs in a data frame
Hi, I'd like to ask you a question again. It is basically about data frames, NAs and tabulate function. I have this data frame. I already used this in one of the previous questions of mine. It intentionally looks this simple, my real 'df' dataframe is much bigger actually and again, I am not willing to annoy anyone with huge databases... So, my database: id
2016 Aug 14
2
table(exclude = NULL) always includes NA
useNA <- if (missing(useNA) && !missing(exclude) && !(NA %in% exclude)) "ifany" An example where it change 'table' result for non-factor input, from https://stat.ethz.ch/pipermail/r-help/2005-April/069053.html : x <- c(1,2,3,3,NA) table(as.integer(x), exclude=NaN) I bring the example up, in case that the change in result is not intended.
2017 Jun 06
0
integrating 2 lists and a data frame in R
Hi Bogdan, Kinda messy, but: N <- data.frame(N=c("n1","n2","n3","n4")) M <- data.frame(M=c("m1","m2","m3","m4","m5")) C <- data.frame(n=c("n1","n2","n3"), m=c("m1","m1","m3"), I=c(100,300,400))
2017 Jun 06
4
integrating 2 lists and a data frame in R
Dear Bert, thank you for your response. here it is the piece of R code : given 3 data frames below --- N <- data.frame(N=c("n1","n2","n3","n4")) M <- data.frame(M=c("m1","m2","m3","m4","m5")) C <- data.frame(n=c("n1","n2","n3"),
2008 Oct 20
2
R 2.8.0 is released
...n more natural scoping. (PR#11169) o In table(), 'exclude=NULL' now does something also for factor arguments. A new 'useNA' argument allows you to control whether to add NA levels unconditionally or only when present in data. A new convenience function addNA() gives similar functionality by adding NA levels to individual factors. o unlink() tries the literal pattern if it does not match with wildcards interpreted -- this helps with e.g. unlink("a[b") which previously needed to be unlink("a\\[b")....