识别两个数据帧之间的变化

时间:2016-12-31 06:53:06

标签: r

Please see this link to see original question and code:

手动浏览代码。保存M所以我可以再次阅读并继续。使用以下代码段,您应该能够在下载csv后复制问题。

//virtualserver[irules[contains(., "whatIwanttofind")]]

此时我在添加新数据后得到以下信息:

fileUrl <- "https://raw.githubusercontent.com/Kill3rbee/NTS-Test/master/test-2016-12-30.csv"
download.file(fileUrl, destfile = "test.csv")
M <- read.csv("test.csv")

KEYS = c("ShortFileName")
VAL = c("scanDate","Count")
retain.columns = c("Category","OwaspTop10","Severity","scanDate", 
                   "Count", "DaysLate")

####################testing code#################################
# this will be our output
O <- M[KEYS]

# add rows.changed
O$row.changed <- with(M, ifelse(is.old & is.new, "10.Retained",
                                ifelse(is.old, "05.Lost", "00.New")))

# add data from new
original.vars <- retain.columns
for (var in original.vars)
  O[[var]] <- M[[paste0(var, ".new")]]

当我运行以下代码时:

ShortFileName   Category.new    OwaspTop10.new  Severity.new    scanDate.new    Count.new   DaysLate.new    is.new  Category.old    OwaspTop10.old  Severity.old    scanDate.old    Count.old   DaysLate.old    is.old
_posix.py   Command Injection   A01-Injection   High    12/5/2016   4   15  TRUE    Command Injection   A01-Injection   High    10/25/2016  4   56  TRUE
11_ro.jsp   Cross-Site Request Forgery  A08-CSRF    Medium  11/16/2016  4   34  TRUE    NA  NA  NA  NA  NA  NA  FALSE
aais_agent.C    Integer Overflow    NA  High    12/2/2016   3   18  TRUE    Insecure Compiler Optimization  NA  Low 10/13/2016  1   68  TRUE
aais_agent.C    Integer Overflow    NA  High    12/2/2016   3   18  TRUE    Buffer Overflow: Format String  NA  High    10/13/2016  6   68  TRUE
aais_agent.C    Integer Overflow    NA  High    12/2/2016   3   18  TRUE    Dangerous Function: strcpy()    NA  Low 10/13/2016  342 68  TRUE
aais_agent.C    Integer Overflow    NA  High    12/2/2016   3   18  TRUE    String Termination Error    NA  High    10/13/2016  834 68  TRUE
aais_agent.C    Integer Overflow    NA  High    12/2/2016   3   18  TRUE    Integer Overflow    NA  High    10/13/2016  3   68  TRUE
aais_agent.C    Insecure Compiler Optimization  NA  Low 12/2/2016   1   18  TRUE    Unchecked Return Value  NA  Low 10/13/2016  11  68  TRUE
aais_agent.C    Buffer Overflow: Format String  NA  Critical    12/2/2016   12  18  TRUE    String Termination Error    NA  High    10/13/2016  834 68  TRUE
aais_agent.C    Buffer Overflow: Format String  NA  Critical    12/2/2016   12  18  TRUE    Integer Overflow    NA  High    10/13/2016  3   68  TRUE
aais_agent.C    String Termination Error    NA  High    12/2/2016   1377    18  TRUE    Unchecked Return Value  NA  Low 10/13/2016  11  68  TRUE



ShortFileName   Category.new    OwaspTop10.new  Severity.new    scanDate.new    Count.new   DaysLate.new    is.new  Category.old    OwaspTop10.old  Severity.old    scanDate.old    Count.old   DaysLate.old    is.old
xmlTranscode.cpp    NA  NA  NA  NA  NA  NA  FALSE   Buffer Overflow: Format String  NA  High    10/13/2016  1   68  TRUE
xmlTranscode.cpp    NA  NA  NA  NA  NA  NA  FALSE   Path Manipulation   NA  Critical    10/13/2016  1   68  TRUE
XMLUtils.java   NA  NA  NA  NA  NA  NA  FALSE   Path Manipulation   NA  High    10/20/2016  4   61  TRUE
XSLHelper.java  NA  NA  NA  NA  NA  NA  FALSE   XML External Entity Injection   A01-Injection   High    10/24/2016  1   57  TRUE
XslMerger.java  NA  NA  NA  NA  NA  NA  FALSE   XML External Entity Injection   A01-Injection   High    10/10/2016  1   71  TRUE
XsltGen.java    NA  NA  NA  NA  NA  NA  FALSE   Path Manipulation   NA  High    10/25/2016  2   56  TRUE
yui-bridge.js   NA  NA  NA  NA  NA  NA  FALSE   Cross-Site Request Forgery  A08-CSRF    Medium  10/21/2016  2   60  TRUE
yuitest-debug.js    NA  NA  NA  NA  NA  NA  FALSE   Cross-Site Request Forgery  A08-CSRF    Medium  10/25/2016  1   56  TRUE
yuitest.js  NA  NA  NA  NA  NA  NA  FALSE   Cross-Site Request Forgery  A08-CSRF    Medium  10/25/2016  1   56  TRUE

我得到以下输出:

# modify data for retain.columns
# Columns for which the NAs should be 
# filled with the 'old' data if rows were lost
# These columns have row.changed value of "05.Lost"
for (var in retain.columns)
  O[[var]] <- ifelse(M$is.new, M[[paste0(var, ".new")]],
                     M[[paste0(var, ".old")]])

它适用于基于上面原始帖子链接的mtcars数据。但是,根据我的数据类型,它无法正常工作。

我不明白为什么它会创建一个包含数字的数据框?

我一直试图找出一种只用* .old后缀列复制旧数据的方法。

我尝试了类似的东西并且有效:

ShortFileName   row.changed Category    OwaspTop10  Severity    scanDate    Count   DaysLate
XSLTTransformer.java    00.New  35  1   2   8   9   23
XsltUtils.java  10.Retained 35  1   2   15  1   16
XSLUtil.java    10.Retained 35  1   2   1   1   58
XSLXReader.java 10.Retained 21  NA  2   19  3   83
XSLXReader.java 10.Retained 21  NA  2   13  3   18
XSSFilter.java  00.New  23  NA  3   4   4   33
XSSFilter.java  00.New  25  NA  3   4   9   33
XSSFilter.java  00.New  19  NA  3   4   2   33
Zoom.java   10.Retained 21  NA  1   14  4   17
Zoom.java   10.Retained 21  NA  1   14  4   17
Zoom.java   10.Retained 9   3   1   14  4   17
Zoom.java   10.Retained 9   3   1   14  4   17
XmlGenericParser.java   05.Lost 33  NA  2   11  1   56
yui-bridge.js   05.Lost 13  5   4   7   2   60
yuitest-debug.js    05.Lost 13  5   4   11  1   56
yuitest.js  05.Lost 13  5   4   11  1   56

然而,这不起作用:

# add data from new
original.vars <- retain.columns
for (var in original.vars)
  if(O$row.changed=="00.New"||O$row.changed=="10.Retained"){
    O[[var]] <- M[[paste0(var, ".new")]]
  }

这是预期结果的一个例子:

# add data from old to Lost
original.vars <- retain.columns
for (var in original.vars)
  if(O$row.changed=="05.Lost"&& is.na(O$Category)){
    O[[var]] <- M[[paste0(var, ".old")]]
  }

我要做的就是所有的row.changed ==&#34; 05.Lost&#34;。我想获取旧数据并替换retain.columns的NA。

提前谢谢

这是lukeA所建议的:

ShortFileName   row.changed Category    OwaspTop10  Severity    scanDate    Count   DaysLate
AbstractCorbaIntf.java  00.New  Poor Error Handling: Empty Catch Block  NA  Low 11/17/2016  1   33
AbstractCorbaIntf.java  00.New  Poor Error Handling: Overly Broad Catch NA  Low 11/17/2016  3   33
AbstractCorbaIntf.java  00.New  System Information Leak NA  Low 11/17/2016  2   33
AbstractDaemon.java 00.New  System Information Leak NA  Low 11/2/2016   1   48
AbstractDaemon.java 00.New  Unchecked Return Value  NA  Low 11/2/2016   1   48
AbstractDatabaseLoader.java 10.Retained Path Manipulation   NA  High    12/5/2016   1   15
AbstractEventListener.java  00.New  Poor Error Handling: Overly Broad Catch NA  Low 11/2/2016   1   48
AbstractEventListener.java  00.New  System Information Leak NA  Low 11/2/2016   1   48
AbstractEventListener.java  00.New  Unsafe Reflection   NA  Low 11/2/2016   2   48
AbstractHostKeyVerification.java    10.Retained XML External Entity Injection   A01-Injection   High    11/28/2016  1   22
AbstractLertFaxController.java  00.New  Often Misused: File Upload  NA  Medium  10/31/2016  1   50
AbstractLertFaxController.java  00.New  Path Manipulation   NA  Critical    10/31/2016  1   50
AbstractMastarsCorbaClientTest.java 10.Retained Path Manipulation   NA  High    11/22/2016  6   28
AbstractTemplateVariableParser.java 10.Retained XML External Entity Injection   A01-Injection   High    12/4/2016   2   16
AbstractTemplateVariableParser.java 10.Retained XML External Entity Injection   A01-Injection   High    12/5/2016   1   15
AbstractTransformerQueryProcessor.java  00.New  Poor Logging Practice: Use of a System Output Stream    NA  Low 11/2/2016   2   48
AbstractXMLDOMConfigurator.java 10.Retained XML External Entity Injection   A01-Injection   High    12/4/2016   2   16
axis2.xml   05.Lost Axis 2 Misconfiguration: Debug Information  A05-Security Misconfig  Medium  10/24/2016  8   57
axis2.xml   05.Lost Axis 2 Misconfiguration: Insecure Message Security  A05-Security Misconfig  Medium  10/23/2016  2   58
axis2.xml   05.Lost Axis 2 Misconfiguration: Insecure Message Security  A05-Security Misconfig  Medium  10/24/2016  2   57
axis2.xml   05.Lost Axis 2 Misconfiguration: Insecure Transport Receiver    A05-Security Misconfig  Medium  10/23/2016  2   58
axis2.xml   05.Lost Axis 2 Misconfiguration: Insecure Transport Receiver    A05-Security Misconfig  Medium  10/24/2016  2   57
UsageMetrics.java   05.Lost Often Misused: Authentication   A02-Broken Auth & Session Management    High    10/7/2016   4   74
UsageMetrics.java   05.Lost Path Manipulation   NA  High    10/18/2016  5   63
usageMetricsReport.jsp  05.Lost Cross-Site Request Forgery  A08-CSRF    Medium  10/25/2016  1   56
UsageMetricsState.java  05.Lost Path Manipulation   NA  High    10/18/2016  5   63

0 个答案:

没有答案