How can I merge two datasets? (Specific example, European Social Survey)

84 Views Asked by At

I am new to R and stick to given commands of the script, since I want to merge two Data Sets and do not know how to do it. (That is the script I am following: https://philippejoly.net/files/code/ess-east-west/vignette.html; I already have the other Dataset (ESS8) imported in my environment).

The code from the script says:

spssfiles <- file.path("data", "raw") %>% 
  list.files() %>%
  .[(str_detect(., "ESS[:digit:]csDE.(por|sav)"))]

Since I only know how to save my data in specific folders, I changed Rs working directory to the folder where I saved the Data set and ran the code:

spssfiles <- file.path("~/Desktop/data/raw") %>% 
  list.files() %>%
  .[(str_detect(., "ESS[:digit:]csDE.(por|sav)"))]

I think that worked.

The next command from the script is:

for (i in seq_along(spssfiles)) {
  rootname <- str_sub(spssfiles[i], end = -5)
  spssfilepath <- file.path("data", "raw", spssfiles[i])
  rdafilepath <- file.path("data", paste0(rootname, ".Rda"))
  read.spss(spssfilepath, use.value.labels = F, to.data.frame = T) %>%
    as_tibble() %>%
    saveRDS(file = rdafilepath)
}

When I want to run this command, I get the answer

Error in read.spss(spssfilepath, use.value.labels = F, to.data.frame = T) :    unable to open file: 'No such file or directory'

I do not know what I made wrong, but since I am a beginner, I probably forgot something. Can someone help? Thanks a lot?

0

There are 0 best solutions below