First of all. I'm new in R, so this is probably pretty simple .
I’m trying to use the package “ISCO08ConveRsions” to assign corresponding job prestige scores (SIOPS, ISEI), to given ISCO-88 codes (you don’t have to understand what all this means, however that is what ISCO08ConveRsions does).
However. When I’m running the code, I’m getting an error message if my argument contains more than one number.
Below I first show an example of some code which works (because the argument only contains one number), and then an example where I get the error message.
library(ISCO08ConveRsions)
example1<- c("1000")
(isei08_1 <- isco08toisei08_2(example1))
# [1] 62
example2 <- c("1000","2364", "4567")
(isei08_2 <- isco08toisei08_2(example2))
# Error in switch(isco08, `0000` = { : EXPR must be a length 1 vector
What am I doing wrong, when the argument contains more than one number? Is there a way of making the function convert more than one number at the time? Please help me out.
The below code should help solve the error. The samples that you shared i.e. 2364 and 4567 are not valid ISCO-08 codes and will give you an error Error in FUN(X[[i]], ...) : Invalid ISCO08-Code
#1. Create a list of ISCO-08 Codes that you wish to work with
my_sample_list<-list("1000","1221","9629")
#2. Use the lapply function to assign scores to each code from the sample list
lapply(my_sample_list, isco08toisei08_2)
Below is how the output of the above code looks like:
[[1]]
[1] 62
[[2]]
[1] 66
[[3]]
[1] 20
You can also use the below code to make the output a bit more intuitive:
library(dplyr)
#1. Create a list of ISCO-08 Codes that you wish to work with
my_sample_list<-list("1000","1221","9629")
#2. Use the lapply function to assign the scores to each code from the sample list and matrix function to give a tabular view
lapply(my_sample_list, isco08toisei08_2) %>%
matrix(nrow=1,ncol=length(my_sample_list),dimnames = list(c("ISEI-08 Score"),c(my_sample_list)))
Below is how the output of the above code looks like: