DataTx DataTx - 4 months ago 7
R Question

How to determine where first integer/float value starts in a list

I have a data frame with several columns. The last column has NA's for, say, the first 50 rows. There are brute methods, but how do I write something that can tell where the first integer/float value starts?

structure(list(col1 = c(646, 574, 590, 671, 618, 529), col2 = c(438,
744, 730, 748, 507, 479), col3 = c(493, 661, 651, 715, 582, 571
), col4 = c(1047, 1252, 1335, 1269, 1185, 1147), col5 = c(883,
1008, 996, 1019, 901, 846), col6 = c(824, 840, 766, 776, 868,
927), col7 = c(727, 685, 708, 779, 717, 721), col8 = c(NA_real_,
NA_real_, NA_real_, NA_real_, NA_real_, NA_real_)), .Names = c("col1",
"col2", "col3", "col4", "col5", "col6", "col7", "col8"), row.names = c(NA,
6L), class = "data.frame")


For the first 7 columns I iterate through, isolate the column and put it into a time series model

for(colin 1:ncol(so)){

isoColumn<- so[,col]

model<-tbats(isoColumn)
}


Is there a programming method/algorithm I can use to tell where the first value is so I can truncate those rows before I plug it into the tbats model?

Answer

You could use which(!is.na(x))[1] to locate the first non-NA value, but why not just do

models <- lapply(so,function(x) tbats(na.omit(x)))

?