I have some problems with my R data preparation (imported from SPSS), and wasn´t able to find a solution in the web.
Problem: Extract labels for subgroup from data frame:
I have a data frame with 42 variables (columns) and another data frame I made for labels. I generated the label data frame with this code:
labelspss <- read.spss("Ma.sav")
la <- as.data.frame(attr(labelspss, "variable.labels"))
la$`attr(labelspss, "variable.labels")`<- as.character(la$`attr(labelspss, "variable.labels")`)
Column 0 contains the variable names; column 1 contains the labeling from SPSS. Now I want to extract these labels for the subgroup of 42 columns and add it to my data.
I´ve already done it manual for another data frame: created a vector for labels and labeled with package hmisc.
But now 42 variables are too much to do it this way. I think I need something that makes a named character vector out of the label data frame. Something that extracts the variable name from rownames (for defined numbers of rows, like eg 140-150) and sets it to the variable label in column 1. I think then I could use label() from the Hmisc package and do the rest.
Thanks for any help!
您可以使用tibble::rownames_to_column()
提取行名。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.