[英]How to use a list name as character
I would like to train a model and give it a name.我想训练一个模型并给它一个名字。 I would like to use this name as character as well to create a text file with model summary.
我也想使用这个名称作为字符来创建一个带有模型摘要的文本文件。 So I created a function as below
所以我创建了一个函数如下
C50Training<-function(ModeName,DF_Trai,Form,
Str_PathSum){
library(C50);
ModeName<-C5.0(formula=Form,data=DF_Trai);
capture.output(summary(ModeName),file=paste(Str_PathSum,"/Summ",ModeName,".txt",sep=""));
}
In the funtion I want to use ModeName as characters.在函数中,我想使用 ModeName 作为字符。 I tried to run it but it does not work.
我试图运行它,但它不起作用。 ModelName is a list in this case.
在这种情况下,ModelName 是一个列表。 How can I use ModelName as character?
如何使用 ModelName 作为字符?
To change a variable name to string, you can use deparse and substitute, as follows:要将变量名称更改为字符串,可以使用 deparse 和替换,如下所示:
deparse(substitute(ModeName))
It return "ModeName" that can be part of your file path.它返回“ModeName”,它可以是文件路径的一部分。
I tried this.我试过这个。 It works.
有用。
ModeName=c(1,2,3)
f<-function(ModeName){
print(paste("/Summ",deparse(substitute(ModeName)),".txt",sep=""))
}
f(ModeName)
and this works too:这也有效:
ModeName=c(1,2,3)
f<-function(list){
print(paste("/Summ",deparse(substitute(list)),".txt",sep=""))
}
f(ModeName)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.