Reputation: 189
I have something like:
wavelength plt1 plt2
1 404.502 0.01451395 0.01394186
2 411.006 0.01538372 0.01455814
...
74 989.878 0.25398372 0.25955116
75 996.382 0.25714419 0.25986279
interpolated1 <- approx(mydata$wavelength, y=NULL, method = "linear", n = 371)
which works for one col. I want to transpose, then interpolate each row to get 371 values in the same range as the original, e.g.
apply(mydata_transposed, 1, approx)
, throws no error but returns no interpolation. I want to specify my interpolation interval.
Thanks in advance.
Upvotes: 0
Views: 542
Reputation: 2085
ting = "wavelength plt1 plt2
404.502 0.01451395 0.01394186
411.006 0.01538372 0.01455814
989.878 0.25398372 0.25955116
996.382 0.25714419 0.25986279"
data <- read.table(text = ting, header = TRUE)
interpolated1 <- apply(data, 2, function(x) approx(x, y=NULL, method = "linear", n = 371)$y)
dim(interpolated1)
# [1] 371 3
head(interpolated1)
# wavelength plt1 plt2
# [1,] 404.5020 0.01451395 0.01394186
# [2,] 404.5547 0.01452100 0.01394686
# [3,] 404.6075 0.01452805 0.01395185
# [4,] 404.6602 0.01453511 0.01395685
# [5,] 404.7129 0.01454216 0.01396185
# [6,] 404.7657 0.01454921 0.01396684
Upvotes: 1