Santiago Sotelo
Santiago Sotelo

Reputation: 316

Get the sub colnames of a dataframe from SPSS to R (read.spss)

i'm new to stack overflow, i have a question.

When i import a dataframe from spss to R with the function read.spss it appears in the colnames two elements: the name of the column and a "sub name" of the column like in the image below:

image in Rstudio

This "sub-colnames" refers to the column Label in SPSS (variable View) like in the image below: enter image description here

My question is: Is there a function that can tell me in the console all the sub-colnames like with the function colnames(dataframe) ? Also, this function could tell me the colname and the subcolname of each column at the same time?

Thanks

Upvotes: 0

Views: 748

Answers (2)

Santiago Sotelo
Santiago Sotelo

Reputation: 316

Thanks @Abdessabour Mtk for your answer, I used it to came with this efficient solution:

labels <- attr(enaho17.2, "variable.labels")                                                   
labels <- data.frame(labels)                                                                    
number <- which(rownames(labels) == "**P203**")                                              
rownames(labels)[number]; labels[number, ]                                              
rownames(labels)

Upvotes: 0

Abdessabour Mtk
Abdessabour Mtk

Reputation: 3888

According to help(read.spss) the attribute variable.labels has the columns labels

df <- read.spss("file")
attr(df, "variable.labels")

Upvotes: 1

Related Questions