Reputation: 161
I have imported an SPSS .sav file using the library foreign read.spss function.
dataset = read.spss("data.sav", to.data.frame=TRUE)
I want to access the column descriptions but can't work out how to access them programmatically. I can see these in the data viewer in RStudio, in the header just below the bold column names.
Image here: https://i.sstatic.net/PgIO5.png
Upvotes: 14
Views: 12457
Reputation: 2828
The list of variable labels can be accessed with attributes(dataset)$variable.labels
.
Upvotes: 2
Reputation: 4349
You may be better off importing the data using the read_sav
function from the haven package (another great package from Hadley Wickham).
dd <- read_sav("SomeFile.sav")
head(dd)[,1:10]
methods(as_factor)
table(dd$District)
class(dd$District)
class(dd$Date)
lapply(dd, class) # some variables have labels and others don't
lapply(dd, class) %>% head
dd$Region
attributes(dd$Region)
attr(dd$Region, 'label')
attr(dd$Region, 'label') <- 'a new label for Region'
attr(dd$Region, 'label')
attr(dd$Region, 'labels')
names(attr(dd$Region, 'labels')) <- c("NE","Nyanza","West")
attr(dd$Region, 'labels')
Upvotes: 21