Export labelled table from read_ipums_micro into .csv file

I’m using the following method to import the labelled data into R for manipulation:

if (!require("ipumsr")) stop("Reading IPUMS data into R requires the ipumsr package. It can be installed using the following command: install.packages('ipumsr')")

ddi <- read_ipums_ddi("usa_00003.xml")
data <- read_ipums_micro(ddi)

My question is, when I export the table after I have cleaned the it, how could I keep the label instead of the code in the .csv file? For example, I want the output .csv file to show the SEX column as “male”, “female” but now it shows 1 and 2.

Thanks!

The ipumsr package includes functions that help read in the available metadata associated with your data extract. Using these functions, you will be able to add in variable labels and value labels.