小编Jor*_*ama的帖子

从箱线图和图表中删除异常值

我试图在R中创建一个没有显示异常值的情节箱图,我在官方页面中找到了这个链接:https://plot.ly/ggplot2/box-plots/#outliers

library(plotly)
set.seed(123)

df <- diamonds[sample(1:nrow(diamonds), size = 1000),]

p <- ggplot(df, aes(cut, price, fill = cut)) + 
geom_boxplot(outlier.shape = NA) + 
ggtitle("Ignore outliers in ggplot2")

# Need to modify the plotly object and make outlier points have opacity equal 
to 0
p <- plotly_build(p)

p$data <- lapply(p$data, FUN = function(x){
 x$marker = list(opacity = 0)
 return(x)
})


# Create a shareable link to your chart
# Set up API credentials: https://plot.ly/r/getting-started
chart_link = plotly_POST(p, filename="geom_boxplot/outliers")
chart_link
Run Code Online (Sandbox Code Playgroud)

问题是,在他们的网页和我的控制台中,仍然显示异常值. …

r ggplot2 shiny plotly

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

矢量的ofstream指针

这是我的问题,我需要创建X个文件并根据不同的事实写入它们,我的解决方案是创建一个像这样的ofstream指针向量

#include <boost/algorithm/string.hpp>
#include <vector>
#include<string>
#include <iostream>
#include <fstream>
vector<ofstream*> files;
files.resize(SplitVec.size()-4);
          for(i=0;i<SplitVec.size()-4;i++)
          {
              line="/Users/jorge/Desktop/testing/strain_"+lexical_cast<string>(i);
              cout<<"ine"<<endl;
              files[i]=new ofstream(line.c_str());
          }
Run Code Online (Sandbox Code Playgroud)

直到这一部分,它创建文件很好,后来在程序中我写给他们,这也很棒,我的问题是当我想要关闭对象,如果我使用:

for(i=0;i<SplitVec.size()-4;i++)
          {
              *files[i].close();
          }
Run Code Online (Sandbox Code Playgroud)

我收到以下错误:

In file included from main.cpp:14:./methyl.h:298: error: request for member 'close' in 'files. std::vector<_Tp, _Alloc>::operator[] [with _Tp = std::ofstream*, _Alloc = std::allocator<std::ofstream*>](1ul)', which is of non-class type 'std::ofstream*'
Run Code Online (Sandbox Code Playgroud)

所以,我有一个问题,首先,为什么我不能调用close,它是指向ofstream的指针,所以使用*files [i],我会想象我可以关闭它,其次,如果我不关闭它,程序工作正常,但我几乎可以肯定,这是一个不好的做法,不想成为一个懒惰或蹩脚的程序员,我尽可能多地看,但我没有找到答案.谢谢!!!

c++ error-handling pointers vector ofstream

5
推荐指数
2
解决办法
6211
查看次数

C++在if语句中声明变量

我在c ++中有一个非常基本的问题,我正在读取一个制表符分隔文件,我想要声明一个带有维度的数组,如果文件有的字段数(使用不同宽度的不同文件),所以我需要阅读第一行并计算字段数,我试过这个:

while(getline(t, line));{
...
if(!flag)
{int array[size][5];
flag=1}
...
}
Run Code Online (Sandbox Code Playgroud)

但后来我得到了错误:

错误:此范围内未声明'array'

我理解这是因为变量的范围在if循环中,有没有办法声明一个空数组并调整它的大小?或者我必须使用指针?

c++ declaration

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

标签 统计

c++ ×2

declaration ×1

error-handling ×1

ggplot2 ×1

ofstream ×1

plotly ×1

pointers ×1

r ×1

shiny ×1

vector ×1