David Moore
David Moore

Reputation: 968

Generating smoothing splines for multiple columns at once

Is there a way to apply the splinefun function to several columns of time-series data at once? Here are some example data:

Index <- c(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
A <- c(3, 4, 3, 3, 3, 5, 6, 7, 6, 4)
B <- c(4, 6, 8, 7, 5, 4, 3, 2, 2, 2)
df <- as.data.frame(cbind(Index, A, B))

I tried to do

lapply(df[, 2:3], splinefun(df$Index, df[, 2:3]))

but that doesn't work.

Upvotes: 1

Views: 278

Answers (1)

C. Braun
C. Braun

Reputation: 5211

How about:

list_of_functions <- lapply(df[, 2:3], function(col) splinefun(df$Index, col))

Upvotes: 1

Related Questions