Here is my complete code that runs with no error.
library(tidyr)
library(dplyr)
DF <- data.frame(Nr_crt = 1:10,
AImin = round(rnorm(10),2),
BImin = round(rnorm(10),2),
AImax = round(rnorm(10),2),
BImax = round(rnorm(10),2),
AEmin = round(rnorm(10),2),
BEmin = round(rnorm(10),2),
AEmax = round(rnorm(10),2),
BEmax = round(rnorm(10),2))
DF
#> Nr_crt AImin BImin AImax BImax AEmin BEmin AEmax BEmax
#> 1 1 0.03 -0.58 -1.26 -0.28 1.51 0.32 -0.18 2.09
#> 2 2 1.35 -0.51 -0.64 -0.74 -0.35 0.47 2.38 0.04
#> 3 3 0.40 -1.23 0.29 -0.39 -0.63 0.03 0.10 0.54
#> 4 4 0.56 -0.74 0.71 -1.65 0.90 0.60 0.01 -1.11
#> 5 5 0.49 1.39 0.86 -0.45 -1.32 -1.26 0.17 -1.03
#> 6 6 -0.92 2.27 -1.31 1.65 -0.64 0.46 -0.37 1.28
#> 7 7 -0.43 0.06 -1.47 -0.54 -2.46 -1.16 0.03 -0.05
#> 8 8 0.14 0.59 0.58 -1.06 0.22 -0.06 0.82 -0.12
#> 9 9 -1.37 0.71 0.98 -0.47 -1.08 0.66 -0.02 -0.22
#> 10 10 -0.09 0.26 -1.26 0.61 1.41 0.60 -0.54 0.29
DFlong <- DF |> pivot_longer(AImin:BEmax) |>
mutate(CAP = substr(name, 1,1),
Poz = substr(name,2,2),
Tip = substr(name,3,5),
Nr_crt2 = row_number())
DFlong
#> # A tibble: 80 x 7
#> Nr_crt name value CAP Poz Tip Nr_crt2
#> <int> <chr> <dbl> <chr> <chr> <chr> <int>
#> 1 1 AImin 0.03 A I min 1
#> 2 1 BImin -0.58 B I min 2
#> 3 1 AImax -1.26 A I max 3
#> 4 1 BImax -0.28 B I max 4
#> 5 1 AEmin 1.51 A E min 5
#> 6 1 BEmin 0.32 B E min 6
#> 7 1 AEmax -0.18 A E max 7
#> 8 1 BEmax 2.09 B E max 8
#> 9 2 AImin 1.35 A I min 9
#> 10 2 BImin -0.51 B I min 10
#> # ... with 70 more rows
DFlong2 <- DFlong |> select(Nr_crt=Nr_crt2,Val=value,CAP,Tip,Poz)
DFlong2
#> # A tibble: 80 x 5
#> Nr_crt Val CAP Tip Poz
#> <int> <dbl> <chr> <chr> <chr>
#> 1 1 0.03 A min I
#> 2 2 -0.58 B min I
#> 3 3 -1.26 A max I
#> 4 4 -0.28 B max I
#> 5 5 1.51 A min E
#> 6 6 0.32 B min E
#> 7 7 -0.18 A max E
#> 8 8 2.09 B max E
#> 9 9 1.35 A min I
#> 10 10 -0.51 B min I
#> # ... with 70 more rows
Created on 2022-07-17 by the reprex package (v2.0.1)
If you still get an error, please show your data and all of the code leading up to the error.