Error in pivot(): could not find function pivot() with tidyverse 1.2.1

Hi,

I might have missed something, but I can't run the pivot() function.
image

I have a problem similar (if not identical) to # http://stackoverflow.com/questions/33599665.

Tried the solution in https://github.com/tidyverse/tidyr/issues/215, but I cannot solve the "multiple-gather" problem.

Would it be possible for you to help?

Set sample:

> dat_group
# A tibble: 8 x 9
  Tag   `Group Area: St~ `Group Area: Gr~ `Group Area: Fa~ `Group Area: No~ `Group CV [%]: ~ `Group CV [%]: ~
  <chr>            <dbl>            <dbl>            <dbl>            <dbl>            <dbl>            <dbl>
1 Cn_M~             194.             204.             132.            128.              65.9            19.3 
2 Cn_M~            6998.           10956.            3149.           4293.              34.6            30.8 
3 Cn_M~             665.             631.             482.            422.              30.5            17.9 
4 Cn_M~            4706.            3121.            2674.           2814.              33.0            50.0 
5 Cn_M~           13192.           20147.           11013.          12207.              33.0             9.06
6 Cn_M~            4797.            3628.            3063.           3302.              38.1            12.7 
7 Cn_M~             175.             122.             120.             84.4             80.4             8.15
8 Cn_M~            3863.            1545.            2862.           2041.             232.             42.5 
# ... with 2 more variables: `Group CV [%]: Fallow, Zero, n, CW` <dbl>, `Group CV [%]: No-tillage, Zero, n, CW` <dbl>

I need to gather "Group Area" and "Group CV[%]" for each group and sample.

Before I had only 1 variable (Group Area) and I achieved the result with:

dat_group_long <- dat_group %>% 
  gather(key = "Sample_ID", value = "Group_area", starts_with("Group Area:")) %>% 
  nest() %>% 
  mutate(Land_use = map(data, ~str_split_fixed(string = str_replace_all(.$Sample_ID, "Group Area: ", ""),
                                               pattern = ",",
                                               n = 4)[,1]),
         Incubation = map(data, ~str_split_fixed(string = str_replace_all(.$Sample_ID, "Group Area: ", ""),
                                               pattern = ",",
                                               n = 4)[,2]),
         Resin_trt = map(data, ~str_split_fixed(string = str_replace_all(.$Sample_ID, "Group Area: ", ""),
                                               pattern = ",",
                                               n = 4)[,3]),
         Extraction = map(data, ~str_split_fixed(string = str_replace_all(.$Sample_ID, "Group Area: ", ""),
                                               pattern = ",",
                                               n = 4)[,4])) %>% 
  unnest() %>% 
  mutate_at(.vars = vars(Land_use:Extraction), .funs = str_replace_all, # removing whitespace
            pattern = " ", replacement = "") %>% 
  select(c(Land_use:Extraction), everything())

Now I have to get the same result, but for both variables.

I am very short with the time for this commitment, and I would be grateful for your help.

Sorry for the hassle,

Cheers

I believe the function you are looking for is pivot_longer, rather than simply pivot, which as the error states is not a function.

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.