作者Wush978 (柴人)
看板Statistics
标题[问题] [R] 请问有办法抓出变数的 代号 吗?
时间Tue Mar 31 22:28:21 2009
我举例说明我想要得到的output好了 (我不太清楚确实的用词要怎麽说)
就是我想要写一个类似name的function
假定叫做name1好了
可以说丢什麽东西进去,他会传回该变数的名称,但是是以字串的形式
ex:
name1(test) 会得到output "test"
---
test <- 1:10
name1(test) 还是会得到output "test"
name1( length(test) ) 会得到 "length(test)"
---
请问R有办法写出这样的function吗?
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 118.161.115.173
※ 编辑: Wush978 来自: 118.161.115.173 (03/31 22:28)
1F:→ lin15:跟直接打"test" 有不一样吗? 03/31 23:25
2F:→ clickhere:这问题有点怪, 你想要做啥呢? computing with text? 04/01 00:34
我想要用function的形式把它写出来
因为我在写自己用的function的时候
output的格式我想用到
例如:
我写一个function 比大小
compare <- function(a,b) {
if (a>b) {
cat(
paste(
name1(a),">",name1(b)
)
)
}
然後呢
compare(2^4,3^2)
就会output
"2^4 > 3^2"
这样子
※ 编辑: Wush978 来自: 118.161.176.44 (04/01 10:28)
3F:推 clickhere:function(a,b) 中 a, b 要用 expression 输入. 04/01 11:04
4F:→ clickhere:你要的就是 computing with text. Try google. 04/01 11:05
5F:→ clickhere:John M. Chambers 2008 Chapter 8 04/01 11:06
6F:→ clickhere:Software for Data Analysis. Programming with R 04/01 11:07
7F:→ clickhere:Springer 04/01 11:07
8F:→ Wush978:谢谢 04/01 12:41