Using an approximate function for grouped data in R

I have a large dataset with columns Id, Vg, Device, Die, W, L and others (not relevant to this question). I want Vg interpolation for a given Id value, but this operation should be performed on the data grouped by the Device and Die column.

My sample data looks like

Die     Device      Id      Vg     W   L 
  1    Device1       1       0    10   1  
  1    Device1     1.2     0.1    10   1  
  1    Device1     1.3     0.2    10   1
  1    Device2       1       0    10   2
  1    Device2     1.2     0.1    10   2  
  1    Device2     1.3     0.2    10   2
  1    Device3       1       0    10   3
  1    Device3     1.2     0.1    10   3  
  1    Device3     1.3     0.2    10   3

Each stamp has 22 unique devices. There are 67 stamps and 22 device names on each matrix are the same. Therefore, if I interpolate Vg for Id = 1.25, I expect to get 22 * ​​67 Vg values ​​for Id = 1.25.

Here is the code I'm trying

data_tidy%>%
  group_by(Die,Device)%>% #Die is numeric, Device is factor
  mutate(Vt=approx(x=log10(Id),y=Vg,xout=log10(3e-8*W/L))$y)

This is similar to what is suggested here , and I copy the suggested code from the link below

df %>%
  group_by(variable) %>%
  arrange(variable, event.date) %>%
  mutate(time=seq(1,n())) %>%
  mutate(ip.value=approx(time,value,time)$y) %>%
  select(-time)

However, when I execute my code above, an error message appears

: 18

0
1

data.table:

library(data.table)
f <- function(x) setDT(df)[,approx(Id,Vg,x), by=list(Device,Die)]
f(1.25)
#     Device Die    x    y
# 1: Device1   1 1.25 0.15
# 2: Device2   1 1.25 0.15
# 3: Device3   1 1.25 0.15

y .

+1

Source: https://habr.com/ru/post/1607717/


All Articles