Hi everybody. The question: I get two vectors 'iFalseFalse' and 'i2'. I think they should be the same but they are not. Is it because R does not handle complicated logical expressions in such cases or I do something wrong?> z1 = c(NA, "", 3, NA, "", 3) > z2 = c("", "", 3, NA, 3, NA) > cV = (as.character(z1)==as.character(z2)) > cV[1] NA TRUE TRUE NA FALSE NA> > iFalse = (c(1:(length(z1))))[(cV==FALSE)] > iNonNA = (c(1:(length(z1))))[(!(is.na(cV)))] > iFalse[1] NA NA 5 NA> > iNonNA[1] 2 3 5> > iFalseFalse = intersect(iFalse, iNonNA) > iFalseFalse[1] 5> i2 = (c(1:(length(z1))))[( (cV==FALSE)&&(!(is.na(cV))) )] > i2numeric(0)>-- Svetlana Eden Biostatistician II School of Medicine Department of Biostatistics Vanderbilt University
You need know about the difference between & and && (and between | and ||). Andy> From: Svetlana Eden > > Hi everybody. > > The question: > I get two vectors 'iFalseFalse' and 'i2'. > I think they should be the same but they are not. > Is it because > R does not handle complicated logical expressions in such cases > or I do something wrong? > > > > z1 = c(NA, "", 3, NA, "", 3) > > z2 = c("", "", 3, NA, 3, NA) > > cV = (as.character(z1)==as.character(z2)) > > cV > [1] NA TRUE TRUE NA FALSE NA > > > > iFalse = (c(1:(length(z1))))[(cV==FALSE)] > > iNonNA = (c(1:(length(z1))))[(!(is.na(cV)))] > > iFalse > [1] NA NA 5 NA > > > > iNonNA > [1] 2 3 5 > > > > iFalseFalse = intersect(iFalse, iNonNA) > > iFalseFalse > [1] 5 > > i2 = (c(1:(length(z1))))[( (cV==FALSE)&&(!(is.na(cV))) )] > > i2 > numeric(0) > > > > -- > Svetlana Eden Biostatistician II School of Medicine > Department of Biostatistics Vanderbilt > University > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html > >------------------------------------------------------------------------------ Notice: This e-mail message, together with any attachments,...{{dropped}}
You want to use & instead of &&. --Matt -----Original Message----- From: r-help-bounces at stat.math.ethz.ch [mailto:r-help-bounces at stat.math.ethz.ch]On Behalf Of Svetlana Eden Sent: Friday, February 27, 2004 7:57 AM To: r-help Subject: [R] question Hi everybody. The question: I get two vectors 'iFalseFalse' and 'i2'. I think they should be the same but they are not. Is it because R does not handle complicated logical expressions in such cases or I do something wrong?> z1 = c(NA, "", 3, NA, "", 3) > z2 = c("", "", 3, NA, 3, NA) > cV = (as.character(z1)==as.character(z2)) > cV[1] NA TRUE TRUE NA FALSE NA> > iFalse = (c(1:(length(z1))))[(cV==FALSE)] > iNonNA = (c(1:(length(z1))))[(!(is.na(cV)))] > iFalse[1] NA NA 5 NA> > iNonNA[1] 2 3 5> > iFalseFalse = intersect(iFalse, iNonNA) > iFalseFalse[1] 5> i2 = (c(1:(length(z1))))[( (cV==FALSE)&&(!(is.na(cV))) )] > i2numeric(0)>-- Svetlana Eden Biostatistician II School of Medicine Department of Biostatistics Vanderbilt University ______________________________________________ R-help at stat.math.ethz.ch mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
Svetlana Eden wrote:> Hi everybody. > > The question: > I get two vectors 'iFalseFalse' and 'i2'. > I think they should be the same but they are not. > Is it because > R does not handle complicated logical expressions in such cases > or I do something wrong? > > > >>z1 = c(NA, "", 3, NA, "", 3) >>z2 = c("", "", 3, NA, 3, NA) >>cV = (as.character(z1)==as.character(z2)) >>cV > > [1] NA TRUE TRUE NA FALSE NA > >>iFalse = (c(1:(length(z1))))[(cV==FALSE)] >>iNonNA = (c(1:(length(z1))))[(!(is.na(cV)))] >>iFalse > > [1] NA NA 5 NA > >>iNonNA > > [1] 2 3 5 > >>iFalseFalse = intersect(iFalse, iNonNA) >>iFalseFalse > > [1] 5 > >>i2 = (c(1:(length(z1))))[( (cV==FALSE)&&(!(is.na(cV))) )] >>i2 > > numeric(0) > >Each line's results as expected. In the last line, you are going to use "&" instead of "&&"! Uwe Ligges
I do not manage to make a Fisher?s exact test with the next matrix : [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [1,] 1 3 0 1 2 9 0 0 2 5 8 6 [2,] 0 3 3 0 0 0 0 5 0 3 0 0 [3,] 0 0 0 0 0 10 0 0 0 0 10 0 [4,] 0 2 0 2 6 14 0 0 6 0 10 6 [5,] 0 5 0 0 0 7 0 0 0 2 8 0 [6,] 0 0 1 9 4 7 2 1 4 2 12 5 [7,] 0 6 0 0 0 0 0 0 0 5 1 3 but I do not understand why it does not work since I obtain the next error message :> fisher.test(enfin.matrix)Error in fisher.test(enfin.matrix) : Bug in FEXACT: gave negative key thank you for considering my application c?dric finet