[R] labels to values
John Kane
jrkrideau at yahoo.ca
Wed Jan 9 19:55:31 CET 2008
There probably is an easier way but you put the
value.labels and corresponding numbers into a
data.frame, stick d[,'Y6] into a data frame and merge
the two. Then just add or replace d[,Y6] in the
original data.frame.
Example
# Set up basic data
aa <- 1:15
bb <- letters[1:15]
# Apply attribute to aa
attr(aa, "value.labels") <- bb ; aa
# mock dataset
cc <- data.frame(hhh= sample(aa, 25, replace=TRUE));
cc
# attrubutes and corresponding numberic values
x <- data.frame(jjj=aa, labs=attr(aa,'value.labels'))
;x
# merge
merge(cc, x, by.x="hhh", by.y="jjj" )
--- Matthias Wendel <office at matthiaswendel.de> wrote:
> I couldn't find out how the following to solve:
> There is a column in a data.frame:
>
> > d[, 'Y6']
> [1] 6 3 8 11 8 9 6 8 3 5 10 15 NA 9 8
> 3 8 16 6 6 NA 10 5 2 7 7 6 16 7 15 7 10 12
> 8 7 12 12 16 7 6 8 8
> 15 6 [45] NA 8 99 7 12 8 9 16 7 16 8 7 7
> 1 15 12 8 7 10 7 8 7 8 9 8 6 6 8 6 16 11
> 5 11 11 1 11 3 7 7 10
> 10 10 6 11 [89] 16 NA 1 3 2 10 99 10 3 3 9
> 7 16 99 16 1 10 2 13 13 13 13 13 13 13 13 13 13 13
> 13 13 13 13 13 13 NA 10 16
> 16 NA 6 10 5 11 [133] 11 1 1 1 1 16 1 16 1
> 1 1 1 6 6 6 16 8 16 16 16 16 5 6 10 99 11 11
> 10 6 6 1 1 6 1 11 11
> 16 9 11 16 6 8 8 16 [177] 16 8 6 16 16 12 12
> 12 12 12 12 12 16 9 16 15 12 12 15 10 16 15 4 1
> 2 14 4 4 2 5 NA 1 5 5
> 7 9 5 12 12 NA 16 12 12 12 [221] 12 12 12 12 12 12
> 99 NA 12 12 NA 1 16 1 7 11 5 6 7 1 13 6 8
> 16 2 1 5 16 16 9 8 8
> 8 7 16 8 8 2 8 5 4 6 14 5 [265] 14 8 8 14
> 4 4 8 14 8 14 6 2 3 14 3 16 5 15 15 15 15
> 15 15 15 15 15 15 15 13 13
> 13 13 13 13 13 13 13 13 13 13 13 15 6 NA [309] 12
> 3 9 9 NA 10 16
> attr(,"value.labels")
> Verwaltung
> Servicegesellschaft Waldfriede (SKW)
> Kurzzeitpflege Waldfriede
> 16
> 15
> 14
> Sozialstation
> Krankenpflegeschule Med. Technischer
> Dienst
> 13
> 12
> 11
> Pflege OP
> Funktionsdienst Pflege
> Gynäkologie
> 10
> 9
> 8
> Pflege Chirurgie
> Pflege Innere Ärzte Anästhesie,
> Röntgen
> 7
> 6
> 5
> Ärzte Gynäkologie
> Ärzte Chirurgie Ärzte
> Innere
> 4
> 3
> 2
> Patientenberatung/-betreuung
> 1
>
> I'd like to have the column with the value.labels as
> values. How do I do that?
> Thanks,
> Matthias
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained,
> reproducible code.
>
More information about the R-help
mailing list