用NA代替大于95%百分位数的那些值

时间:2017-09-05 13:07:06

标签: r

我有一个数据框,我想用NA替换那些大于95%百分位数的值。

到目前为止,我已尝试过以下内容:

$(document).ready(function() {
    //Getting the canvas
    var canvas1 = new fabric.Canvas("canvas2");
    var freeDrawing = true;
    var divPos = {};
    var offset = $("#canvas2").offset();
    $(document).mousemove(function(e) {
        divPos = {
            left: e.pageX - offset.left,
            top: e.pageY - offset.top
        };
    });
    $('#2').click(function() {

        console.log("Button 2 cilcked");

        //Declaring the variables
        var isMouseDown = false;
        var refRect;

        //Setting the mouse events
        canvas1.on('mouse:down', function(event) {
            //Defining the procedure
            isMouseDown = true;
            //Getting yhe mouse Co-ordinates
            //Creating the rectangle object
            if (freeDrawing) {
                var rect = new fabric.Rect({
                    left: divPos.left,
                    top: divPos.top,
                    width: 0,
                    height: 0,
                    stroke: 'red',
                    strokeWidth: 3,
                    fill: ''
                });
                canvas1.add(rect);
                refRect = rect; //**Reference of rectangle object
            }

        });

        canvas1.on('mouse:move', function(event) {
            // Defining the procedure

            if (!isMouseDown) {
                return;
            }
            //Getting yhe mouse Co-ordinates
            if (freeDrawing) {
                var posX = divPos.left;
                var posY = divPos.top;

                refRect.setWidth(Math.abs((posX - refRect.get('left'))));
                refRect.setHeight(Math.abs((posY - refRect.get('top'))));
                canvas1.renderAll();
            }

        });


        canvas1.on('mouse:up', function() {
            //alert("mouse up!");
            canvas1.add(refRect);
            isMouseDown = false;
            canvas1.add();
            //freeDrawing=false;  // **Disables line drawing
        });
    });
});

但是我收到以下错误:

<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.5.0/fabric.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<canvas id="canvas2" width=500 height=500 style="height:500px;width:500px;"></canvas>
<img width=500 height=500 alt="" id="scream" src="canvas.png" style="display:none;"/>
<div style="position: relative; width: 1300px; height:30px; border: 2px solid black; margin-top: 5px">
<input type="button" id="2" value="rectangle">

关于如何做的任何想法?

3 个答案:

答案 0 :(得分:2)

假设您的数据如下:

@Override
public void onProgress(final long current, final long max) {
    if (isFirstLoad) {
        progressBarHorizonatl.setProgress(0);
        progressBarHorizonatl.setMax((int) max);
        isFirstLoad = false;
    }
    new Handler(Looper.getMainLooper()).post(new Runnable() {
                        @Override
                        public void run() {
                            Log.d("UI thread", "I am the UI thread");
                            progressBarHorizontal.setProgress((int) current);
                        }
                    });

}

然后您可以按如下方式分配df = data.frame(id = 1:7, value = c(1,2,3,4,5,6,7))

NA

答案 1 :(得分:1)

你必须使用==来获得逻辑声明,因为bouncyball说。请注意,您现在正在替换df $ value等于第95个百分位数的所有行,因此您可能希望将该逻辑语句更改为

{{1}}

还指定要更改的列。错误消息表明您的列中已有NA。为了排除这些以计算正确的分位数,请在函数中将na.rm(na remove)设置为等于。

答案 2 :(得分:1)

添加

quantile(..., na.rm=T)

摆脱错误