Hi,
It is possible however it is a bit problematic due to the format of the data. The data needs a lot of wrangling and it would have been better to have it in a tidy format. You can check more about tidy format in the following article. It will help you in any situation in which you work with data, not just this one.
On the other hand, you might need the data in this specific format so I have posted below the code, that will transform your data in a tidy format, will bring it in one dataset, replace the missing values with 0's and transform the data back in the original format.
The code might not be the best elegant, however it will do what you need.
library(tidyverse)
# We will create some additional datasets to help in better transforming them
df0_longer <- df0 %>% pivot_longer(colnames(df0), names_to = "Species", values_to = "Density_0")
df10_longer <- df10 %>% pivot_longer(colnames(df10), names_to = "Species", values_to = "Density_10")
df20_longer <- df20 %>% pivot_longer(colnames(df20), names_to = "Species", values_to = "Density_20")
df5_longer <- df5 %>% pivot_longer(colnames(df5), names_to = "Species", values_to = "Density_5")
# We will create a list of all the species in all the tables so we can take them all into accout
df <- df0_longer["Species"] %>%
rbind(df10_longer["Species"]) %>%
rbind(df20_longer["Species"]) %>%
rbind(df5_longer["Species"]) %>%
distinct()
# Now that we have all the species in one column, we can bring the density information using left_join()
df <- df %>%
left_join(df0_longer, by = "Species") %>%
left_join(df10_longer, by = "Species") %>%
left_join(df20_longer, by = "Species") %>%
left_join(df5_longer, by = "Species") %>%
# And to replace missing values with 0's
mutate(across(everything(), ~ ifelse(is.na(.), 0, .)))
# Now we need to transform the data back and bind it to each other
final_df <- df %>% select(Species, Density_0) %>% pivot_wider(names_from = "Species", values_from = "Density_0") %>%
rbind(df %>% select(Species, Density_10) %>% pivot_wider(names_from = "Species", values_from = "Density_10")) %>%
rbind(df %>% select(Species, Density_20) %>% pivot_wider(names_from = "Species", values_from = "Density_20")) %>%
rbind(df %>% select(Species, Density_5) %>% pivot_wider(names_from = "Species", values_from = "Density_5"))
I hope this helps!