作者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