小编Rub*_*ens的帖子

使用cbind聚合函数

我正在尝试使用该aggregate功能cbind,但我必须遗漏一些东西.

我已经在使用Aggregate for Multiple Aggregations中看到了我可以简单地定义哪个列我想要修复以及我想添加哪个列,但是我无法得到我期望的结果.

我有:

x <- data.frame(alfa = 1:9, beta = rep(1:3, 3))

  alfa beta
1    1    1
2    2    2
3    3    3
4    4    1
5    5    2
6    6    3
7    7    1
8    8    2
9    9    3
Run Code Online (Sandbox Code Playgroud)

我想检索由beta列中的条目汇总的条目的平均值.为此,我尝试过:

aggregate(cbind(alfa) ~ beta, data = x, FUN = function(x) c(gama = mean(x)) )
Run Code Online (Sandbox Code Playgroud)

这给了我:

  beta alfa
1    1    4
2    2    5
3    3    6
Run Code Online (Sandbox Code Playgroud)

结果不应该是这样的:

  alfa …
Run Code Online (Sandbox Code Playgroud)

aggregate r

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

加速C++中文件的整数读取

我正在逐行读取文件,并从中提取整数.一些值得注意的要点:

  • 输入文件不是二进制文件;
  • 我无法将整个文件加载到内存中;
  • 文件格式(只有整数,由一些分隔符分隔):

    x1 x2 x3 x4 ...
    y1 y2 y3 ...
    z1 z2 z3 z4 z5 ...
    ...
    
    Run Code Online (Sandbox Code Playgroud)

只是为了添加上下文,我正在读取整数,并计算它们,使用std::unordered_map<unsigned int, unsinged int>.

只需循环遍历行,并分配无用的字符串流,如下所示:

std::fstream infile(<inpath>, std::ios::in);
while (std::getline(infile, line)) {
    std::stringstream ss(line);
}
Run Code Online (Sandbox Code Playgroud)

给了我~7.7s的700MB文件.

解析每一行:

unsigned int item;
std::fstream infile(<inpath>, std::ios::in);
while (std::getline(infile, line)) {
    std::stringstream ss(line);
    while (ss >> item);
}
Run Code Online (Sandbox Code Playgroud)

给我~17.8s的同一个文件.

如果我将运算符更改为std::getline+ atoi:

unsigned int item;
std::fstream infile(<inpath>, std::ios::in);
while (std::getline(infile, line)) {
    std::stringstream ss(line);
    while (std::getline(ss, token, ' ')) …
Run Code Online (Sandbox Code Playgroud)

c++ performance parsing fstream

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

查找向量中的最新非缺失值

我正在尝试使用不丢失的值返回向量中的最新行。例如,给定

x <- c(1,2,NA,NA,3,NA,4)
Run Code Online (Sandbox Code Playgroud)

然后,函数(x)将输出类似以下的列表:

c(1,2,2,2,3,3,4)
Run Code Online (Sandbox Code Playgroud)

非常简单的问题,但是在多个列上使用循环或蛮力运行它会永远花费。

r vector missing-data

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

可变模板运算符&lt;&lt;

我试图将我的一些函数更改foo()operator<<(),只是为了让一些“半 C/半 C++”代码看起来更像 C++。但是,发生了,我被困在了以下转换步骤

template <class... T>
inline const size_t foo(const T&... data) {
    return sizeof...(T);
}
struct bar {
    template <class... T>
    inline const size_t operator<<(const T&... data) {
        return sizeof...(T);
    }
};
int main(int argc, char *argv[]) {
    bar a;
    std::cout << ">>> length " << foo(1, 2, 3) << std::endl;
    std::cout << ">>> length " << (a << 1 << 2) << std::endl;
    std::cout << ">>> length " << (a << …
Run Code Online (Sandbox Code Playgroud)

c++ operator-overloading variadic-templates

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

元组内的元组错误

我正在尝试获取表示元组元素的整数值,元组本身是另一个元组的元素.

a1 = (1,1,2,3)
a2 = (3,1,1,2)
a3 = (2,3,1,1)
a4 = (1,2,3,1)

a = [a1, a2, a3, a4]

print(a[1[1]])
Run Code Online (Sandbox Code Playgroud)

结果是:'TypeError: 'int' object is unsubscriptable'.我怎样才能得到正确的答案(因为a2的第二个条目是1,所以是1)?

python tuples

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

无法在linux上安装python瓶

python bottle在linux上安装框架时遇到问题.以下是我从中获得的信息uname -a:

Linux magzilla 3.2.0-38-generic#61-Ubuntu SMP Tue Feb 19 12:18:21 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

我已经安装python 2.7.3,并pip在其上.它们都成功建立.下载bottle 0.11框架后,我尝试安装它,使用sudo apt-get install python-bottle,我得到以下内容:

sudo apt-get install python-bottle Reading package lists... Done
Building dependency tree        Reading state information... Done You
might want to run 'apt-get -f install' to correct these: The following
packages have unmet dependencies:  linux-server : Depends:
linux-headers-server (= 3.2.0.39.47) but 3.2.0.53.63 is to be
installed E: …
Run Code Online (Sandbox Code Playgroud)

python bottle

0
推荐指数
1
解决办法
387
查看次数

如何将导航栏固定到底部而不是顶部

这里的问题是我的导航栏位于fixed顶部,我希望它fixed位于底部:

<html>
<body>
<center>
<h1>My Resume</h1>
<link rel="stylesheet" type="text/css" href="csstrial.css">
<center>

<div id="nav">
<p class="title"><a href="#">TheCodePress<span class="subtitle">.blogspot.com</span>              </a></p>
<ul id="navigation">
<li><a href="#">Home</a></li>
<li><a href="#">My Blog</a></li>
<li><a href="#">Tutorials</a></li>
<li><a href="#">Downloads</a></li>
<li><a href="#">About</a></li>
</ul>
</div>


<nav>
<ul>
<li><a href="home.html" target='MYHOME'>Home</a></li>
<li><a href="cmon.html" target='MYHOME'>Qualifications</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>


<iframe src="home.html" name="MYHOME" height="550" width="700"
frameborder="0">
Run Code Online (Sandbox Code Playgroud)

这是我的CSS

#nav
 {
 background-color:#262626;
 width:100%;
 height:50px;
 box-shadow: 0px 1px 50px #5E5E5E;
 position:fixed;
 top:0px;
}

.title
 {
 color:#EDEDED;
 font-family:verdana;
 font-size:25px;
 width:350px;
 margin-top:6px;
 margin-left:150px;
 font-weight:bold; …
Run Code Online (Sandbox Code Playgroud)

html css navigation

0
推荐指数
2
解决办法
2万
查看次数

Linux bash-script在所有子目录中运行make

我正在尝试在Linux中编写一个遍历当前目录的bash脚本,并在每个子目录中启动现有的makefile.它应该适用于每个子目录,无论深度如何.

一些限制:

  • 我不能使用Python;
  • 我事先并不知道有多少个子目录及其名称;
  • 我事先并不知道当前目录的名称;
  • make只有在此类文件夹中有makefile时,才应启动每个目录的命令.

关于如何做的任何想法?

bash makefile

0
推荐指数
1
解决办法
1763
查看次数

使用格式字符串打印类

在我的代码中,我只使用格式字符串打印相同的对象.但是,结果并不相同.根据我的见解,我认为结果应该是97 97 97,但结果是97 98 99.

输出怎么了?我实际上并不了解发生了什么.你能解释一下吗?

class A {
public:
    int a, b, c;
    A() {
        this->a = 97;
        this->b = 98;
        this->c = 99;
    };
};

int main(int argc, char **argv) {
    A a;
    printf("%d %d %d\n", a, a, a);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

c++ oop

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