boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - What is R equivalent to SAS format?
相关主题
SAS format 的问题
每个ID出现一次,missing去掉,请问高手用SAS怎么做?
SAS proc format的问题
Proc SQL 能不能直接读 非 SAS format 的数据,txt , csv 等
Help needed on SAS proc report
SAS - please help!
what is the fastest way of look-up in SAS?
Please help me with SAS! Thank you!
急 SAS问题
SAS 编程问题 (有包子)
相关话题的讨论汇总
话题: sas话题: what话题: format话题: mapping话题: fruit
进入Statistics版参与讨论
1 (共1页)
S******y
发帖数: 1123
1
I have a numberical field in an R data frame, say x, which has many values -
1, 2, 3, ..., 999
Each numerical value corresponds to a categorical text value, say -
1 -> 'apple'
2 -> 'pear'
3 -> 'grape'
...
999 ->'other'
In SAS, PROC FORMAT would be very handy to take care of mapping original
value (e.g. 1) to translated values (e.g. 'apple').
But in R, what is the most effiecient way to do this?
thanks!
D******n
发帖数: 2836
2
a<-c(1,1,2,3,1,2,3);
mapping<-c('apple','pear','grape');
na<-mapping[a];

-

【在 S******y 的大作中提到】
: I have a numberical field in an R data frame, say x, which has many values -
: 1, 2, 3, ..., 999
: Each numerical value corresponds to a categorical text value, say -
: 1 -> 'apple'
: 2 -> 'pear'
: 3 -> 'grape'
: ...
: 999 ->'other'
: In SAS, PROC FORMAT would be very handy to take care of mapping original
: value (e.g. 1) to translated values (e.g. 'apple').

S******y
发帖数: 1123
3
Thanks! DaShagen.
That works great!
One more question, what if I need to do some grouping - e.g -
1,2 -> 'good fruit'
2,3,5 --> 'bad fruit'
...
999 -> 'other fruit'
?
D******n
发帖数: 2836
4
mapping<-c('good fruit','good fruit','bad fruit','bad fruit'....)
hehe this looks silly though.

【在 S******y 的大作中提到】
: Thanks! DaShagen.
: That works great!
: One more question, what if I need to do some grouping - e.g -
: 1,2 -> 'good fruit'
: 2,3,5 --> 'bad fruit'
: ...
: 999 -> 'other fruit'
: ?

S******y
发帖数: 1123
5
Thanks. That was helpful!
It would be nice if , for general purpose of recoding variable values, R has
a 'DECODE' function like in SQL.
1 (共1页)
进入Statistics版参与讨论
相关主题
SAS 编程问题 (有包子)
请教一个SAS问题
Re: SAS help : proc format.
问个SAS问题
SAS 求助, 一个小问题, 包子答谢
Easy SAS question, anyone can help
请教如何用SAS处理这个RANDOM SAMPLING的问题
菜鸟问个sas得问题,关于分数组
如何判断一个dataset是不是空的?
[sas] 怎么用自定义format里的值来计算?
相关话题的讨论汇总
话题: sas话题: what话题: format话题: mapping话题: fruit