I wanted to merge two datasets and the merging resulted in getting incomplete strings in a variable
# Librerias
```{r}
library(dplyr)
library(tidyr)
library(tidyverse)
library(readxl)
library(readr)
library(base)
library(stringr)
library(foreign)
library(forcats)
library(fs)
library(hablar)
library(openxlsx)
```
# Comercio CIIU
```{r}
# Mercancias
Catalogo_comercio_CIIU <- read_excel("Comercio/Catalogo comercio bienes CIIU.xlsx") %>%
mutate(ACTIV4=CIIU)
CIIU_Exportaciones <- read_excel("Comercio/CIIU Exportaciones.xlsx") %>%
pivot_longer(cols = -...1, names_to = "Period", values_to = "Valor") %>%
mutate(Flujo="Exportaciones")
CIIU_Importaciones <- read_excel("Comercio/CIIU Importaciones.xlsx") %>%
pivot_longer(cols = -...1, names_to = "Period", values_to = "Valor") %>%
mutate(Flujo="Importaciones")
Length<- CIIU_Exportaciones %>% group_by(...1) %>%
summarise(Obs=n())
Length<- Length$Obs[[1]] %>%
as.numeric() %>%
as.vector()
# Mensual
Comercio_bienes_mensual <- rbind(CIIU_Importaciones, CIIU_Exportaciones) %>%
rename(Actividad="...1") %>% group_by(Flujo, Actividad) %>%
mutate(Fecha=seq(from=as.Date("1994-01-01"), by="month", length.out=Length)) %>%
mutate(Year=str_sub(Fecha, 1L,4L), Mes=str_sub(Fecha, 6L,7L)) %>%
group_by(Flujo, Actividad, Year) %>%
mutate(Acumulado=cumsum(Valor)) %>%
group_by(Flujo, Actividad) %>%
mutate( C_acumulado= Acumulado-lag(Acumulado, n=12L), TC_acumulado=Acumulado/lag(Acumulado, n=12L)-1 ) %>%
merge(Catalogo_comercio_CIIU, by="Actividad") %>%
select(-Grupo,-Detalle,-Categoria1,-Categoria2)
```
This is the catalogue I want to merge
This is how the merging turned out (incomplete string)
I am a beginner so I don't really know what to try