数据框有n列,我想得到n个图,每列一个图.
我是新手,我不会说R,无论如何我找到了两个解决方案.
第一个工作,但它不打印列名称(我需要它们!):
data <- read.csv("sample.csv",header=T,sep=",")
for ( c in data ) plot( c, type="l" )
Run Code Online (Sandbox Code Playgroud)
第二个更好用,因为它打印列名:
data <- read.csv("sample.csv",header=T,sep=",")
for ( i in seq(1,length( data ),1) ) plot(data[,i],ylab=names(data[i]),type="l")
Run Code Online (Sandbox Code Playgroud)
是否有更好的(从R语言的角度来看)解决方案?
使用此代码有什么好处
double x;
double square = pow(x,2);
Run Code Online (Sandbox Code Playgroud)
而不是这个?
double x;
double square = x*x;
Run Code Online (Sandbox Code Playgroud)
我更喜欢x*x并且查看我的实现(Microsoft)我发现pow没有优势,因为x*x比特定方形情况下的pow更简单.
有什么特别的情况,战俘优越吗?
我正在寻找一个OpenCV函数,它可以找到连接的组件并对它们执行一些任务(比如获取像素数,轮廓,对象中的像素列表等).
是否有OpenCV(C++)的功能类似于MatLab的regionprops?
为什么pop_frontC++中没有方法std::vector?
在Visual Studio 2013(版本12.0.31101.00 Update 4)中编译此代码段时没有错误
class A
{
public:
A(){}
A(A &&){}
};
int main(int, char*)
{
A a;
new A(a);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
虽然它在Visual Studio 2015 RC(版本14.0.22823.1 D14REL)中使用此错误进行编译:
1>------ Build started: Project: foo, Configuration: Debug Win32 ------
1> foo.cpp
1>c:\dev\foo\foo.cpp(11): error C2280: 'A::A(const A &)': attempting to reference a deleted function
1> c:\dev\foo\foo.cpp(6): note: compiler has generated 'A::A' here
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)
我认为Visual Studio 2015附带的编译器生成了复制构造函数并将其标记为=delete,因此我得到了错误C2280(顺便说一句,我在msdn.microsoft.com上找不到文档).
现在,假设我有一个可与Visual Studio 2013兼容的代码库(它可以工作,因为它依赖于编译器自动生成的代码)但由于C2280而无法与Visual Studio …
我有这个代码
#include <vector>
#include <iostream>
int main(int argc, char* argv[])
{
std::vector<int> v1,v2;
std::cout << std::distance(v1.begin(),v2.begin());
return 0;
}
Run Code Online (Sandbox Code Playgroud)
它有一个bug,因为比较两个不同向量的迭代器没有意义.
我看了一下N3376在24.4.4迭代器操作在815页:
Run Code Online (Sandbox Code Playgroud)template<class InputIterator> typename iterator_traits<InputIterator>::difference_type distance(InputIterator first, InputIterator last);要求:如果
InputIterator符合随机访问迭代器的要求,last应可以从first或first到达last; 否则,last应该可以从first.
现在我认为需求没有实现.
在这种情况下,标准状态应该发生什么?
有没有一种简单的方法可以找到二维数组中元素的邻居(即元素周围的八个元素)?只需在不同的组合中减去和添加索引,如下所示:
array[i-1][i]
array[i-1][i-1]
array[i][i-1]
array[i+1][i]
Run Code Online (Sandbox Code Playgroud)
... 等等.
您好我有这个代码与编译器错误(错误来自Microsoft Visual Studio 2008):
class B
{
protected:
int b;
};
class A : public B
{
public:
void foo(){ &B::b; }// error C2248: 'B::b' : cannot access protected member declared in class 'B'
};
Run Code Online (Sandbox Code Playgroud)
虽然此代码没有错误:
class B
{
protected:
int b;
};
class A : public B
{
public:
void foo(){ &(B::b); }
};
Run Code Online (Sandbox Code Playgroud)
基于我对运算符优先级的了解,这两个片段在我看来是等价的,因为::具有比&更高的优先级(例如参见"联合攻击战斗机车辆C++编码系统开发和编码标准"第137页的表2)演示计划" http://www2.research.att.com/~bs/JSF-AV-rules.pdf)
但它们是不同的...我认为它与"指向数据成员"有关,但我不知道它如何与运算符优先级相符.
任何解释?
谢谢,亚历山德罗
int myfun()
{
return 42;
}
Run Code Online (Sandbox Code Playgroud)
我知道我可以写
auto myvar = myfun();
Run Code Online (Sandbox Code Playgroud)
但是,如果我只是想声明myvar(不使用常见的typedef)怎么办?
the_type_returned_by_myfun myvar;
Run Code Online (Sandbox Code Playgroud)
什么可以写而不是the_type_returned_by_myfun?
有什么区别
int a;
// a gets some value
double pi = static_cast<double>(a)/3;
Run Code Online (Sandbox Code Playgroud)
和
int a;
// a gets some value
double pi = double(a)/3;
Run Code Online (Sandbox Code Playgroud)
你见过后者吗?在我看来,我在Stroustrup写的一些片段中看到了它,但我找不到参考.