R invalid double index type

I have sample data as below

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

output:

data_tidy <- structure(list(Die = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), Device = c("Device1", 
"Device1", "Device1", "Device2", "Device2", "Device2", "Device3", 
"Device3", "Device3"), Id = c(1, 1.2, 1.3, 1, 1.2, 1.3, 1, 1.2, 
1.3), Vg = c(0, 0.1, 0.2, 0, 0.1, 0.2, 0, 0.1, 0.2), W = c(10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L), L = c(1L, 1L, 1L, 2L, 
2L, 2L, 3L, 3L, 3L)), .Names = c("Die", "Device", "Id", "Vg", 
"W", "L"), class = "data.frame", row.names = c(NA, -9L))

I use the following code snippet to interpolate the value Vgin the specified Id.

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

I get an error

Error: Invalid index type 'double'

I am surprised because I was able to compile this code a few days ago without any errors. I also discussed the code on the forum here . I am not sure what the problem is. Any help would be appreciated.

+4
source share
2 answers

I think the problem is that you are trying to do the following if you break the code.

Vt is an

Vt=approx(x=log10(data_tidy$Id),y=data_tidy$Vg,
xout=log10(3e-8*(data_tidy$W)/(data_tidy$L)))

It gives Vtboth

> Vt
$x
[1] -6.522879 -6.522879 -6.522879 -6.823909 -6.823909 -6.823909 -7.000000 -7.000000
[9] -7.000000

$y
[1] NA NA NA NA NA NA NA NA NA

, x y

> 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)))$x)
Error: invalid subscript type 'double'

double , . , x Vt .

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)))[["x"]])

.

+3

:

https://github.com/hadley/dplyr/issues/1554

dplyr::mutate(df, newColumn = someVariable$'a')
+3

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


All Articles