Thanks for the help! Are you sure R version plays a role in this case? My R version is 2.13.0
Your suggestion prompted me to look into the help content of ifelse, and a similar example exists there: x <- c(6:-4) sqrt(x) #- gives warning sqrt(ifelse(x >= 0, x, NA)) # no warning ## Note: the following also gives the warning ! ifelse(x >= 0, sqrt(x), NA) Based on the above example, now I have a solution for my situation: tConvert2 <- function(tval, DF, fullDF) qt(pt(ifelse(DF>=1, tval, 0), ifelse(DF>=1, DF, 1)), fullDF) > tConvert2(c(2,3), c(0,12), 12) [1] 0 3 However, I feel my solution is a little kludged. Any better idea? Thanks, Gang On Thu, Jul 7, 2011 at 9:04 PM, David Winsemius <dwinsem...@comcast.net>wrote: > > On Jul 7, 2011, at 8:52 PM, David Winsemius wrote: > > >> On Jul 7, 2011, at 8:47 PM, Gang Chen wrote: >> >> I define the following function to convert a t-value with degrees of >>> freedom >>> DF to another t-value with different degrees of freedom fullDF: >>> >>> tConvert <- function(tval, DF, fullDF) ifelse(DF>=1, qt(pt(tval, DF), >>> fullDF), 0) >>> >>> It works as expected with the following case: >>> >>> tConvert(c(2,3), c(10,12), 12) >>>> >>> [1] 1.961905 3.000000 >>> >>> However, it gives me warning for the example below although the output is >>> still as intended: >>> >>> tConvert(c(2,3), c(0,12), 12) >>>> >>> [1] 0 3 >>> Warning message: >>> In pt(q, df, lower.tail, log.p) : NaNs produced >>> >>> I'm confused about the warning especially considering the fact that the >>> following works correctly without such warning: >>> >>> tConvert(2, 0, 12) >>>> >>> [1] 0 >>> >>> What am I missing? >>> >> >> The fact that ifelse evaluates both sides of the consequent and >> alternative. >> > > I also think you should update yur R to the most recent version since a > current version does not issue that warning. > > > -- > David Winsemius, MD > West Hartford, CT > > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.