作者wheado (principal component QQ)
看板R_Language
标题[问题] formula 输入格式问题
时间Tue Oct 17 23:20:06 2017
[问题类型]:
程式谘询(我想用R 做某件事情,但是我不知道要怎麽用R 写出来)
[软体熟悉度]:
入门(写过其他程式,只是对语法不熟悉)
[问题叙述]:
在指令 lm() 中 formula 参数通常都是输入
y~x 当资料变数名称是 x 和 y
如果今天 target <- "y"
接着输入 lm( target~x, data ) 会跑出 error
如果不改变资料内部变数名称的话
要怎麽做才可以把让上面的程式跑得过
谢谢
[程式范例]:
https://ideone.com/dWpek1
[环境叙述]:
R version 3.4.1 (2017-06-30)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
[关键字]:
formula
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 119.14.8.71
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/R_Language/M.1508253611.A.CF9.html
1F:→ celestialgod: lm(as.formula(paste0(target, "~x")), data) 10/17 23:52
2F:→ wheado: 谢谢大大,感激不尽 10/17 23:55