作者Tolkien (怪獸)
看板R_Language
標題[問題] eval 使用問題
時間Fri Feb 6 04:16:44 2015
[問題類型]:
程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
[軟體熟悉度]:
請把以下不需要的部份刪除
新手(matlab background)
[問題敘述]:
字串變變數
[程式範例]:
在matlab 字串矩陣要寫入迴圈中我會用:
run = { 'net' 'fsns' 'flns' }
for in=1:3
eval(['' run{in} 'Var_sum1=sum(' run{in} '_people'])
endif
這個代表我執行
netVar_sum1 =sum (net_people)
fsnsVar_sum1 =sum (fsns_people)
flsnVar_sum1 =sum (flns_people)
請問在R 要如何把字串矩陣寫入迴圈
我的Code:
run=c('net,'fsns','flns')
for(i in 1:3){
????????????
}
但還是不行
請高手幫幫忙 謝謝
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 144.39.205.79
※ 文章網址: https://www.ptt.cc/bbs/R_Language/M.1423167407.A.82B.html
→ andrew43: eval( parse(text = "code字串") ) 02/06 05:44
→ andrew43: 所以在loop中先把整個code轉成字串, 02/06 05:46
推 andrew43: 再送到 eval(parse(text="字串")) 就可以了。 02/06 05:46
→ andrew43: 前面的字串處理可以用 paste() 來做。試試看。 02/06 05:47
→ Tolkien: 謝謝 02/06 06:29