I think you mean to use if instead of ifelse (and you should probably read briefly on the difference between them: if is the regular programming construct: ifelse is a vectorized thing)
if(length(theData) == 0) t0 <- t0 else t0 <- theData which can be more expressly written as t0 <- if(length(theData)==0) t0 else theData Michael Weylandt On Tue, Oct 25, 2011 at 4:05 AM, hchui <helena.c...@flinders.edu.au> wrote: > Hi there, > > I have the following problem using times() and ifelse(). > > t0 <- c(rep("NA", 7)) > theData <- times(c("07:36:00","08:09:00","10:28:00","13:28:00","16:29:00", > "19:30:00","22:29:00")) > t0 <- ifelse(length(theData)==0, t0,theData) > > In this case, R gives this, instead of theData: > >> t0 > [1] 0.3166667 > > Is there a way to fix it? Any hint is welcome. > > Many thanks, > Helena > > -- > View this message in context: > http://r.789695.n4.nabble.com/Library-chron-tp3935969p3935969.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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. > ______________________________________________ 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.