问题列表 - 第36336页

用于"左连接"两个数据帧的惯用R方法

我有两个数据框,它们都有一个包含如下因素的列:

> head(test.data)
      var0     var1       date  store
1 109.5678 109.5678 1990-03-30 Store1
2 109.3009 108.4261 1990-06-30 Store1
3 108.8262 106.2517 1990-09-30 Store1
4 108.2443 108.6417 1990-12-30 Store1
5 109.5678 109.5678 1991-03-30 Store1
6 109.3009 108.4261 1991-06-30 Store1
> summary(test.data)
      var0             var1              date                store   
 Min.   : -9.72   Min.   : -2.297   Min.   :1990-03-30   Store1 : 8  
 1st Qu.: 68.32   1st Qu.: 71.305   1st Qu.:1990-09-07   Store2 : 8  
 Median :102.19   Median :101.192   Median :1991-02-13   Store3 : 8  
 Mean   :101.09   Mean   :103.042   Mean   :1991-02-13 …
Run Code Online (Sandbox Code Playgroud)

loops idioms join r

1
推荐指数
2
解决办法
237
查看次数

如何组织复杂类的单元测试?

我有一个复杂的类(300多行),我试图从不同的"观点"进行测试.我已经创建了三个不同的单元测试.每个测试本身都是一个复杂的类(100多行).问题是 - 在项目目录树中存储它们的最佳位置是什么?这就是我现在正在做的事情(使用Maven):

pom.xml
/src
  /main
    /java
      /com
        /Foo
          ComplexClass.java
  /test
    /java
      /com
        /Foo
          /ComplexClass
            FirstPointOfViewTest.java
            SecondPointOfViewTest.java
            ThirdPointOfViewTest.java
Run Code Online (Sandbox Code Playgroud)

当然,名称只是占位符,用于解释问题/问题.您如何看待这种方法?

java

4
推荐指数
1
解决办法
1043
查看次数

如何使用jQuery获取HTML表格的第一行的最后一列

我有一个html表,我需要获取第一行的值或文本(不是thead部分,它将在tbody部分中)。我需要点击按钮的值btnAdd

 <table>
    <thead>
    <tr>
    <td>Name</td>
    <td>ID</td>
    </tr>
    </thead>
    <tbody>
    <tr>
    <td>Edwin</td>
    <td><span style='display:none'>1</span></td>
    </tr>
    </tbody>
    </table>
   <input type='btnAdd' runat='server' >
Run Code Online (Sandbox Code Playgroud)

html jquery

2
推荐指数
1
解决办法
5096
查看次数

字符串包含

在我的Intranet页面上,我有以.doc或.xls结尾的链接.

如何使用jQuery检查它们是否以.xls结尾,这样我就可以为这些链接添加一些javascript

编辑:

这不起作用:

$("a.resultLink").live('click', function(event)
{
    // do something here
    // ...

    // change .doc link behaviour
    var anchor = $("a:contains('.doc')"); 
    if (anchor){ 
        event.preventDefault(); 
        alert("this is a doc");
    } 

    // do something else here
    // ...
});
Run Code Online (Sandbox Code Playgroud)

jquery jquery-selectors

2
推荐指数
1
解决办法
342
查看次数

使用boost.python而不是bjam

我只是想编译boost.python的"hello world"示例而不使用所有的bjam魔法.我的boost.python安装工作正常,我用bjam成功构建了示例并通过了测试套件.

现在,对于我的项目,我需要在普通的Make环境中使用所有这些东西.我不想移植到另一个构建工具.

所以我的天真方法当然只是将包含路径指向正确的标题并链接到正确的库.我将boost python构建为system-layout,static,runtime-static,这意味着它只是一个驻留在/ usr/local/lib中的libboost_python.a.

不幸的是,我在生成的.so库中得到了未解析的外部符号.

这是我尝试从libs/python/example/tutorial/hello.cpp构建示例:

$ cat hello.cpp
//  Copyright Joel de Guzman 2002-2004. Distributed under the Boost
//  Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt
//  or copy at http://www.boost.org/LICENSE_1_0.txt)
//  Hello World Example from the tutorial
//  [Joel de Guzman 10/9/2002]

#include <boost/python/module.hpp>
#include <boost/python/def.hpp>

char const* greet()
{
   return "hello, world";
}

BOOST_PYTHON_MODULE(hello_ext)
{
    using namespace boost::python;
    def("greet", greet);
}

$ g++ -I/usr/local/include -I/usr/include/python -fpic -c -o hello.o
hello.cpp
$ g++ -shared -Wl,-soname,"libhello.so" …
Run Code Online (Sandbox Code Playgroud)

makefile bjam boost-python

8
推荐指数
1
解决办法
7814
查看次数

传输换行符"\n"

给出以下URL(工作,试试吧!)

https://select-test.wp3.rbsworldpay.com/wcc/purchase?instId=151711&cartId=28524¤cy=GBP&amount=1401.49&testMode=100&name=Tom%20Gul&address=24%20House%20Road \nSome Place \nCounty&postcode = TR33%20999&email = email@mail.com&country=GB

如果单击链接并转到付款页面,则地址框中的地址显示不正确,换行符将显示为文本.

我尝试过,<br />'s但没有运气,有人有任何想法吗?我需要使用换行符显示地址.

逗号可以作为分隔符,但我更希望能够有换行符.谢谢你的帮助!一个工作的例子将是公认的答案.

url html-encode html-entities

130
推荐指数
4
解决办法
13万
查看次数

javascript中的动态对象构造?

当我想在javascript中使用从其他地方提供的参数调用函数时,我可以使用apply函数的方法,如:

array = ["arg1", 5, "arg3"] 
...
someFunc.apply(null, array);
Run Code Online (Sandbox Code Playgroud)

但是如果我需要以类似的方式调用构造函数呢?这似乎不起作用:

array = ["arg1", 5, "arg3"] 
...
someConstructor.apply({}, array);
Run Code Online (Sandbox Code Playgroud)

至少不是我在尝试:

template = ['string1', string2, 'etc'];
var resultTpl = Ext.XTemplate.apply({}, template);
Run Code Online (Sandbox Code Playgroud)

这不起作用:

Ext.XTemplate.prototype.constructor.apply({}, template);
Run Code Online (Sandbox Code Playgroud)

有什么办法使这个工作吗?(在这个特殊情况下,我发现它new Ext.XTemplate(template)会起作用,但我对一般情况感兴趣)

类似的问题,但特定于内置类型,没有我可以使用的答案: 通过调用prototype.constructor.apply实例化JavaScript对象

谢谢.

编辑:

时间已经过去,ES6和转换器现在已成为一件事.在ES6中,做我想做的事是微不足道的:new someConstructor(...array). Babel会将其转换为ES5 new (Function.prototype.bind.apply(someConstructor, [null].concat(array)))();,如何构建JavaScript对象(使用'apply')中进行了解释?.

javascript dynamic-languages

18
推荐指数
2
解决办法
8865
查看次数

强制XDocument使用UTF-8编码写入String

我希望能够使用声明和UTF-8编码将XML写入String.这似乎很难完成.

我已经阅读了一些并尝试了一些流行的答案,但他们都有问题.我当前的代码正确输出为UTF-8但不保持XDocument的原始格式(即缩进/空格)!

有人可以提供一些建议吗?

XDocument xml = new XDocument(new XDeclaration("1.0", "utf-8", "yes"), xelementXML);

MemoryStream ms = new MemoryStream();
using (XmlWriter xw = new XmlTextWriter(ms, Encoding.UTF8))
{
    xml.Save(xw);
    xw.Flush();

    StreamReader sr = new StreamReader(ms);
    ms.Seek(0, SeekOrigin.Begin);

    String xmlString = sr.ReadToEnd();
}
Run Code Online (Sandbox Code Playgroud)

XML要求格式化与格式化格式相同,.ToString()

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<root>
    <node>blah</node>
</root>
Run Code Online (Sandbox Code Playgroud)

我现在看到的是

<?xml version="1.0" encoding="utf-8" standalone="yes"?><root><node>blah</node></root>
Run Code Online (Sandbox Code Playgroud)

更新 我已经设法通过添加XmlTextWriter设置让这个工作...虽然看起来非常笨重!

MemoryStream ms = new MemoryStream();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
settings.ConformanceLevel = ConformanceLevel.Document;
settings.Indent = true;
using (XmlWriter xw …
Run Code Online (Sandbox Code Playgroud)

c# xml utf-8 linq-to-xml

36
推荐指数
1
解决办法
4万
查看次数

== vs C等于#

在C#中评估==和Equals有什么区别?

对于Ex,

if(x==x++)//Always returns true
Run Code Online (Sandbox Code Playgroud)

if(x.Equals(x++))//Always returns false 
Run Code Online (Sandbox Code Playgroud)

编辑:

     int x=0;
     int y=0;

     if(x.Equals(y++))// Returns True
Run Code Online (Sandbox Code Playgroud)

.net c# equality operators

14
推荐指数
1
解决办法
916
查看次数

将字典<string,string>转换为c#中以分号分隔的字符串

简单的开始一天,给出Dictionary<string, string>如下:

var myDict = new Dictionary<string, string>();
myDict["A"] = "1";
myDict["B"] = "2";
myDict["C"] = "3";
myDict["D"] = "4";
Run Code Online (Sandbox Code Playgroud)

我想创建一个字符串: "A=1;B=2;C=3;D=4"

一个示例实现:

var myStringBuilder = new StringBuilder();
bool first = true;
foreach (KeyValuePair<string, string> pair in myDict)
{
    if (first)
    {
        first = false;
    }
    else
    {
        myStringBuilder.Append(";");
    }

    myStringBuilder.AppendFormat("{0}={1}", pair.Key, pair.Value);
}

var myDesiredOutput = myStringBuilder.ToString();
Run Code Online (Sandbox Code Playgroud)

请注意,字典可能少于10个项目,这表明StringBuilder过度.

哪些替代实施更简洁/高效?框架是否有任何有用的功能?

c#

125
推荐指数
3
解决办法
9万
查看次数