[R] Find the first occurrence in a list

Glenn Schultz glennmschultz at me.com
Mon Mar 14 18:41:35 CET 2016


All,

I am looking to find the first principal payment date on structured MBS cash flow.  I am testing the below to make into a function the correct index is returned.  I am a little unsure. Is this the correct way to think about this problem or is there something already in R that can help?

Glenn

 data <- as.list(c(rep(0, 20), rep(1, 340)))

  f <- function(x){x != 0}

  which(sapply(data, f ) == TRUE)[1]
  
	[[alternative HTML version deleted]]



More information about the R-help mailing list