I have a large tibble (here). I created it by using this original dataset and running the following (previous post here):
#this code seemed to work
library(tidyverse)
df_tib <- df_full_subset %>%
pivot_longer(cols = everything(), names_to = c("name", ".value"), names_pattern = "(.*)_(.*)") %>%
select(-name) %>%
pivot_wider(names_from = "01", values_from = "02", values_fn = list)
As can be seen in the previous post, there was a final bit of code to unnest that data. That didn't work for me so I tinkered with the tibble and found a few rubbish columns (e.g. a column of NAs), and removed those thinking that might help. However, I keep getting the same error: "Error: Incompatible lengths: 254, 257"
. This reads to me like dplyr
is struggling with NAs in rows 254 and 257, but I've seen other posts where this seems to be easily dealt with (like this one that used filter
), and those solutions did not work for this data.
#cleaning the data
df_tib$habitat <- df_tib$habitat_
df_tib$species <- df_tib$species_
df_tib <- janitor::clean_names(df_tib)
df_tib <- df_tib %>%
select(-habitat_,-species_, -na)
df_tib <- df_tib %>%
unnest(cols = everything()) #does not work
Any help is very appreciated.