0

I have a multiple tibble in a list, later the data were unlisted using rbindlist. With these data I try to transform from long format to wide format, but the factor used to get this result is different in each case, and this affects the spread function and it is impossible to obtain the data.

This is the source to output the


[991]]
# A tibble: 1 x 5
  species                 measure                         min   max value  
  <chr>                   <chr>                         <int> <int> <chr>  
1 Ellisella hemisphaerica mineralized skeleton contains    NA    NA calcite

[[992]]
# A tibble: 1 x 5
  species           measure                         min   max value  
  <chr>             <chr>                         <int> <int> <chr>  
1 Ellisella calamus mineralized skeleton contains    NA    NA calcite

[[993]]
# A tibble: 1 x 5
  species             measure                         min   max value  
  <chr>               <chr>                         <int> <int> <chr>  
1 Ellisella funculina mineralized skeleton contains    NA    NA calcite

[[994]]
# A tibble: 27 x 5
   species      measure                             min    max value                 
   <chr>        <chr>                             <dbl>  <dbl> <chr>                 
 1 Ellisellidae ecomorphological guild             NA     NA   "planktonic"          
 2 Ellisellidae habitat is                         NA     NA   "marine benthic biome"
 3 Ellisellidae latitude                          -34.4   38.2 "degrees"             
 4 Ellisellidae longitude                        -159.   168.  "degrees"             
 5 Ellisellidae mineralized skeleton contains      NA     NA   "calcite"             
 6 Ellisellidae number of DNA Records In GGBN       0      0   "show all records"    
 7 Ellisellidae number of public records in BOLD   18     18   ""                    
 8 Ellisellidae number of records in BOLD          54     54   ""                    
 9 Ellisellidae number of records in GBIF        7161   7161   ""                    
10 Ellisellidae number of references in BHL        49     49   ""                    
# ... with 17 more rows

[[995]]
# A tibble: 4 x 5
  species             measure                       min   max value               
  <chr>               <chr>                       <int> <int> <chr>               
1 Exaiptasia diaphana ecomorphological guild         NA    NA planktonic          
2 Exaiptasia diaphana habitat is                     NA    NA marine benthic biome
3 Exaiptasia diaphana mineralized tissue contains    NA    NA no                  
4 Exaiptasia diaphana trophic level                  NA    NA carnivore           

[[996]]
NULL

[[997]]
# A tibble: 18 x 5
   species               measure                                   min     max value                                                  
   <chr>                 <chr>                                   <dbl>   <dbl> <chr>                                                  
 1 Leptogorgia virgulata ecomorphological guild                 NA       NA    planktonic                                             
 2 Leptogorgia virgulata geographic distribution includes       NA       NA    North Atlantic                                         
 3 Leptogorgia virgulata habitat is                             NA       NA    marine benthic biome                                   
 4 Leptogorgia virgulata has habitat                            NA       NA    limestone                                              
 5 Leptogorgia virgulata is eaten by                          1758     1758    Centropristis philadelphica (Linnaeus ) (rock sea bass)
 6 Leptogorgia virgulata latitude                               11.3     37.4  degrees                                                
 7 Leptogorgia virgulata longitude                             -97.2    -70.7  degrees                                                
 8 Leptogorgia virgulata mineralized skeleton contains          NA       NA    calcite                                                
 9 Leptogorgia virgulata skeleton structure                     NA       NA    condensed                                              
10 Leptogorgia virgulata Supporting Structures and Enclosures   NA       NA    show all records   endoskeleton                        
11 Leptogorgia virgulata water depth                             2.4    220    m                                                      
12 Leptogorgia virgulata water dissolved O2 concentration        4.52     4.90 mL/L                                                   
13 Leptogorgia virgulata water nitrate concentration             0.325    2.01 µmol/L                                                 
14 Leptogorgia virgulata water O2 saturation                    94.7    101.   percent                                                
15 Leptogorgia virgulata water phosphate concentration           0.1      0.18 µmol/L                                                 
16 Leptogorgia virgulata water salinity                         35.6     36.2  PSU                                                    
17 Leptogorgia virgulata water silicate concentration            0.756    1.52 µmol/L                                                 
18 Leptogorgia virgulata water temperature                      23.5     24.3  degrees Celsius                                        

[[998]]
# A tibble: 2 x 5
  species                measure                       min   max value            
  <chr>                  <chr>                       <int> <int> <chr>            
1 Macrorhynchia ramulosa mineralized tissue contains    NA    NA calcium phosphate
2 Macrorhynchia ramulosa trophic level                  NA    NA carnivore        

[[999]]
# A tibble: 28 x 5
   species              measure                             min    max value                                                     
   <chr>                <chr>                             <dbl>  <dbl> <chr>                                                     
 1 Millepora alcicornis conservation status                NA     NA   CITES Appendix II                                         
 2 Millepora alcicornis eats                             1847   1894   Parvocalanus crassirostris (Dahl F. )                     
 3 Millepora alcicornis ecomorphological guild             NA     NA   planktonic                                                
 4 Millepora alcicornis first appearance                   NA     NA   million years ago                                         
 5 Millepora alcicornis geographic distribution includes   NA     NA   South Atlantic                                            
 6 Millepora alcicornis habitat is                         NA     NA   marine benthic biome                                      
 7 Millepora alcicornis has habitat                        NA     NA   subtropical                                               
 8 Millepora alcicornis is eaten by                      1765   1863   Cantherhines macrocerus (Hollard ) (Whitespotted Filefish)
 9 Millepora alcicornis last appearance                    NA     NA   million years ago                                         
10 Millepora alcicornis latitude                          -23.2   32.4 degrees                                                   
# ... with 18 more rows

[[1000]]
# A tibble: 4 x 5
  species              measure                       min   max value            
  <chr>                <chr>                       <int> <int> <chr>            
1 Millepora alcicornis mineralized tissue contains    NA    NA calcium phosphate
2 alcicornis           mineralized tissue contains    NA    NA calcium phosphate
3 Millepora alcicornis trophic level                  NA    NA carnivore        
4 alcicornis           trophic level                  NA    NA carnivore  

Them The rbindlist was called

I<-rbindlist(output[991:1000], use.names = TRUE, fill=TRUE)

This is the line

A1<-I%>% spread(key=measure,value=min)

And the result obtained is

Error: Each row of output must be identified by a unique combination of keys.
Keys are shared for 4 rows:
* 66, 83
* 73, 85

The result desired is a table with the information provided in measure as column names with min, max and value information; however, I don not presented this result because I planning to get with a merge_all with the three final tables.

Table with measure information as column names

  • 1
    I really don't understand what you mean. I don't get what "the factor used to get this result is different" means—what factor? What are you saying is impossible? If all you're trying to do is bind all the data frames row-wise and then reshape to wide, what would be your ID variable? That's the issue that throws this error – camille Jan 27 '20 at 22:02
  • 2
    What are the values of rows 66, 83, 73, and 85? It's possible that those rows aren't displayed in the sample above. – manotheshark Jan 27 '20 at 22:03
  • Perhaps try `I <- I[!duplicated(I),]` before calling `spread` – Allan Cameron Jan 27 '20 at 22:52
  • 1
    Do you want to spread only the `min` value? How would your expected output look? Can you add a reproducible example? – Ronak Shah Jan 28 '20 at 03:57
  • With ``` I <- I[!duplicated(I),] ``` the error does not solve. – Juan Carlos Rubio Polania Jan 28 '20 at 05:39
  • Could you share the output of `dput(I[60:70,])` with us? This should probably make a reproducible example of your error. – Dan Chaltiel Jan 28 '20 at 14:25

0 Answers0