r - 比较两个文件头并确保它们具有相同的头,无论顺序如何
问题描述
我想比较两个配置文件,一个是用户生成的,另一个是模板。
我有代码工作,但觉得有更好的方法来处理这个问题。
#config variable designated previously
current.config.template<-'/location/of/template'
default.config<- read.csv(current.config.template,stringsAsFactors = FALSE)
bool<-colnames(default.config) %in% colnames(config)
for(i in bool){
if(i==FALSE){
stop("Please use the most recent met-ingest.csv file located /path/to/file/")
}
}
它有效,但我觉得必须有一种更好的方法来实现这一点,而不是 for 循环中的 if 循环。
解决方案
你不需要循环。你可以简单地做到这一点 -
if(any(!bool)) {
stop("Please use the most recent met-ingest.csv file located /path/to/file/")
}
推荐阅读
- protobuf-net - 继承类的 Protobuf .NET 序列化
- python - PiCamera 将流数据保存到图像文件中
- html - 引导汉堡导航栏不起作用
- mysql - MySQL以日期时间间隔连接两个表
- javascript - 无法访问 Promise 对象
- unity3d - 如何检索位于列表中特定索引处的游戏对象?
- kotlin - 如何在 Jetty 中使用 SessionContext 配置 SessionHandler?
- java - 需要从 Hibernate SessionFactory 的 XML 定义中引用 String JavaBean
- reactjs - 使用 react-apollo 查询的不同方法
- mysql - mysql如何将多个表合并为一个表