RStudio console output doubled


#1

Hi,

I have weird problem. Some times when I subset a data frame, the output is doubled at the console.

The row number from the actual line is added with 1.

For example, if the row number for the actual line is 12345, then the duplicated line has 123451, and the content on each column is the same as in actual line.

This is highly annoying.

> Q[Q$time_stamp == 1520702581600,]
               id clock      x   y x_velocity y_velocity progress
5175488  a4da22e00154         5124469 -30.02 7.9       5.77      31.59              TRUE
51754881 a4da22e00154         5124469 -30.02 7.9       5.77      31.59              TRUE
         quality    zone time_stamp recording
5175488     0.64 Zone001     1520702581600           48
51754881    0.64 Zone001     1520702581600           48

#2

It’s not clear what is happening here without seeing your code and input data. You should include a reprex with your question.

As is your prose description isn’t sufficient, you also need to make a simple reprex that:

  1. Builds the input data you are using.
  2. The function you are trying to write, even if it doesn’t work.
  3. Usage of the function you are trying to write, even if it doesn’t work.
  4. Builds the output data you want the function to produce.

You can learn more about reprex’s here:

Right now the is an issue with the version of reprex that is in CRAN so you should download it directly from github.

Until CRAN catches up with the latest version install reprex with

devtools::install_github(“tidyverse/reprex”)

The reason we ask for a reprex is that it is the easiest and quickest way for someone to understand the issue you are running into and answer it.

Nearly everyone here who is answering questions is doing it on their own time and they really appreciate anything you can do to minimize that time and make it easier for them to help you.


#3

It’s very hard to tell without your seeing the content of Q and your code what is going on. But my speculation is that Q has two rows with duplicate values and the row name of one is 5175488 and the other is 51754881.

And a further speculation is the when the data.frame Q was built it using rbind to combine two or more data.frames to make Q

Here is an example of what happens with you combine two data.frames the have rows with matching names. Some of the row names end up with numbers appended to keep all row names unique. You can’t build a data.frame with row names that are not unique so rbind “fixes up” the row names as needed so that they do not clash.

In any case this is one of the reasons for including a reprex in your question so that the person who tries to answer it doesn’t have to speculate a lot and build demo code from scratch.

tbl <-tibble::tribble(~a, ~b, ~c, 
   1,2,3,
   1,2,3,
   1,3,4,
   2,7, 9,
   1,6,3,
   2, 8,2)
   
class(tbl) <- c("data.frame")

row.names(tbl) <- c("a", "b", "c", "d", "e", "f")

rbind(tbl, tbl)
#>    a b c
#> a  1 2 3
#> b  1 2 3
#> c  1 3 4
#> d  2 7 9
#> e  1 6 3
#> f  2 8 2
#> a1 1 2 3
#> b1 1 2 3
#> c1 1 3 4
#> d1 2 7 9
#> e1 1 6 3
#> f1 2 8 2

Created on 2018-03-12 by the reprex package (v0.2.0).


#4

Thank you Dan for your kind reply. Unfortunately I already left the office and my work laptop is there.

However I indeed did use rbind.

I download data from our postgres database into R. I could download the whole “record”, but then I would get lot’s of useless rows. Therefore I splitted the “record” by using time stamps (in the query), and then combine those into one data.frame with rbind.

I am sure that the “record” in our database does not have duplicate lines so the problem must be in my R code or Rstudio. But after reading your example I am pretty sure that the problem is in my R code.

I will look into it tomorrow.

Thank you very much!


#5

Just wanted to add that the problem was indeed in my code and how I had used rbind. Thanks again!


#6

Cool — would you mind marking the solution?