我正在尝试解析使用.step
函数生成的 LTSpice 数据。这会将生成的数据集拆分为我不知道如何有效处理的部分R
。
library(tidyverse)
data <- read_tsv("FileName")
##
## ── Column specification ────────────────────────────────────────────────────────
## cols(
## time = col_character(),
## `V(out)` = col_double(),
## `V(in)` = col_double()
## )
## Warning: 24 parsing failures.
## row col expected actual file
## 1 -- 3 columns 1 columns 'FileName'
## 6 -- 3 columns 1 columns 'FileName'
## 11 -- 3 columns 1 columns 'FileName'
## 16 -- 3 columns 1 columns 'FileName'
## 21 -- 3 columns 1 columns 'FileName'
## ... ... ......... ......... ..............................
## See problems(...) for more details.
head(data)
## # A tibble: 6 x 3
## time `V(out)` `V(in)`
## <chr> <dbl> <dbl>
## 1 Step Information: Resistor1=10 Resistor2=1M Offset=-3 (Run… NA NA
## 2 0.000000000000000e+00 -1.50e-5 0
## 3 4.913626562387649e-09 3.08e-2 0.0309
## 4 4.996634374887648e-09 3.13e-2 0.0314
## 5 5.000000000000000e-09 3.14e-2 0.0314
## 6 Step Information: Resistor1=10.01K Resistor2=1M Offset=-3 … NA NA
如您所见,数据被分成几部分,这些部分由有关步骤的信息分隔。我想更改数据,以便删除包含“步骤信息”的行,并将相应的参数写入匹配的列:
## # A tibble: 6 x 6
## time `V(out)` `V(in)` Resistor1 Resistor2 Offset
## <chr> <dbl> <dbl> <lgl> <lgl> <lgl>
## 1 0.000000000000000e+00 -0.0000150 0 NA NA NA
## 2 4.913626562387649e-09 0.0308 0.0309 NA NA NA
## 3 4.996634374887648e-09 0.0313 0.0314 NA NA NA
## 4 5.000000000000000e-09 0.0314 0.0314 NA NA NA
## 5 0.000000000000000e+00 -0.00749 0 NA NA NA
## 6 4.908743749887649e-09 0.00789 0.0308 NA NA NA
编辑:
部分原始数据:
time V(out) V(in)
Step Information: Resistor1=10 Resistor2=1M Offset=-3 (Run: 1/24)
0.000000000000000e+00 -1.498494e-05 0.000000e+00
4.913626562387649e-09 3.082234e-02 3.086832e-02
4.996634374887648e-09 3.134312e-02 3.138962e-02
5.000000000000000e-09 3.136424e-02 3.141076e-02
Step Information: Resistor1=10.01K Resistor2=1M Offset=-3 (Run: 2/24)
0.000000000000000e+00 -7.485015e-03 0.000000e+00
4.908743749887649e-09 7.887614e-03 3.083766e-02
4.996634374887648e-09 8.162769e-03 3.138962e-02
5.000000000000000e-09 8.173305e-03 3.141076e-02
Step Information: Resistor1=20K Resistor2=1M Offset=-3 (Run: 3/24)
...