Итак, у меня есть длинный набор данных. Каждый столбец (от t1 до t ... n) имеет одинаковые уровни или категории. В общей сложности более 200 категорий или уровней и 144 столбца (переменных).Последние разработки в перекодировке повторяющихся переменных в R?
id t1 t2 t3 t...n
"1" "eating" "tv" "conversation" "..."
"2" "sleep" "driving" "relaxing" "..."
"3" "drawing" "kissing" "knitting" "..."
"..." "..." "..." "..." "..."
Переменные t1 имеют одинаковые уровни, равные t2 и т. Д. Что мне нужно, это перекодировка в стиле цикла для каждого столбца (но избегание цикла).
Я хотел бы избежать обычного
seq$t1[seq$t1== "drawing"] <- 'leisure'
seq$t1[seq$t1== "eating"] <- 'meal'
seq$t1[seq$t1== "sleep"] <- 'personal care'
seq$t1[seq$t1== "..."] <- ...
Самый удобный стиль перекодировка будет что-то вроде
c('leisure') = c('drawing', 'tv', ...)
Это помогло бы мне лучше кластерных переменных в большие категории.
Есть ли какие-то новые и более простые методы перекодирования в R, появившиеся в последнее время? Что бы вы посоветовали мне использовать?
Это образец моего реального набора данных, 5 повторных наблюдений (в столбце) для 10 респондентов (в строках).
dtaSeq = structure(c("Wash and dress", "Eating", "Various arrangements", "Cleaning dwelling", "Ironing", "Activities related to sports",
"Eating", "Eating", "Other specified construction and repairs",
"Other specified physical care & supervision of a child", "Wash and dress",
"Filling in the time use diary", "Food preparation", "Wash and dress",
"Ironing", "Travel related to physical exercise", "Eating", "Eating",
"Other specified construction and repairs", "Other specified physical care & supervision of a child",
"Wash and dress", "Filling in the time use diary", "Food preparation",
"Wash and dress", "Food preparation", "Wash and dress", "Eating",
"Eating", "Other specified construction and repairs", "Other specified physical care & supervision of a child",
"Wash and dress", "Filling in the time use diary", "Baking",
"Teaching the child", "Food preparation", "Wash and dress", "Eating",
"Eating", "Other specified construction and repairs", "Other specified physical care & supervision of a child",
"Dish washing", "Unspecified TV watching", "Reading periodicals",
"Teaching the child", "Food preparation", "Reading periodicals",
"Eating", "Eating", "Other specified construction and repairs",
"Feeding the child", "Laundry", "Unspecified TV watching", "Cleaning dwelling",
"Teaching the child", "Eating", "Eating", "Eating", "Eating",
"Other specified construction and repairs", "Feeding the child"),
.Dim = c(10L, 6L), .Dimnames = list(c("1", "2", "3", "4",
"5", "6", "7", "8", "9", "10"), c("act1.050", "act1.051", "act1.052",
"act1.053", "act1.054", "act1.055")))
Укажите, пожалуйста, пример и/или подмножество данных с помощью 'dput()'. Самый простой способ сделать это - это, вероятно, функция 'recode()' из пакета ** car **. – Thomas
'seq [seq ==" sleep "| seq == "расслабляющий"] <- "личная забота"? – Victorp