Quantcast

inadverted reordering of a df column when it is copied to another df

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

inadverted reordering of a df column when it is copied to another df

karl.schilling
Dear all:

I have two data.frames A and B of the same number of rows (about
40,000). I realized that when I copy column x from data.frame A to B,
the order of this column  gets changed. This seems to affect only values
in rownumbers > ~ 35/36,000. It also happens in any of the following
three approaches:

A$x <- B$x

x <- B$x (here, x is still in the correct order)
B$x <- x : now x is reordered

B <- cbind(A, B$x)

I am working with Windows7Pro/64bit, R 3.3.3, and RStudio 0.99.903.

Any help would be appreciated.

Best regards

Karl Schilling

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: inadverted reordering of a df column when it is copied to another df

Thierry Onkelinx
Dear Karl,

This is hard to investigate without a reproducible example.

Best regards,
ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek / Research Institute for Nature
and Forest
team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
Kliniekstraat 25
1070 Anderlecht
Belgium

To call in the statistician after the experiment is done may be no
more than asking him to perform a post-mortem examination: he may be
able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
The plural of anecdote is not data. ~ Roger Brinner
The combination of some data and an aching desire for an answer does
not ensure that a reasonable answer can be extracted from a given body
of data. ~ John Tukey


2017-03-17 16:05 GMT+01:00 Karl Schilling <[hidden email]>:

> Dear all:
>
> I have two data.frames A and B of the same number of rows (about 40,000). I
> realized that when I copy column x from data.frame A to B, the order of this
> column  gets changed. This seems to affect only values in rownumbers > ~
> 35/36,000. It also happens in any of the following three approaches:
>
> A$x <- B$x
>
> x <- B$x (here, x is still in the correct order)
> B$x <- x : now x is reordered
>
> B <- cbind(A, B$x)
>
> I am working with Windows7Pro/64bit, R 3.3.3, and RStudio 0.99.903.
>
> Any help would be appreciated.
>
> Best regards
>
> Karl Schilling
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: inadverted reordering of a df column when it is copied to another df

Bert Gunter-2
In reply to this post by karl.schilling
You are wrong. No reordering occurs.

Cheers,
Bert




Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Fri, Mar 17, 2017 at 8:05 AM, Karl Schilling
<[hidden email]> wrote:

> Dear all:
>
> I have two data.frames A and B of the same number of rows (about 40,000). I
> realized that when I copy column x from data.frame A to B, the order of this
> column  gets changed. This seems to affect only values in rownumbers > ~
> 35/36,000. It also happens in any of the following three approaches:
>
> A$x <- B$x
>
> x <- B$x (here, x is still in the correct order)
> B$x <- x : now x is reordered
>
> B <- cbind(A, B$x)
>
> I am working with Windows7Pro/64bit, R 3.3.3, and RStudio 0.99.903.
>
> Any help would be appreciated.
>
> Best regards
>
> Karl Schilling
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: inadverted reordering of a df column when it is copied to another df

Jeff Newmiller
Reprex confirming Bert:

A <- data.frame( y = 1L:40000L )
B <- data.frame( x = 1L:40000L )
A$x <- B$x
plot(B$x)

#' ![](http://i.imgur.com/cXSFsBh.png)

Care to demonstrate for us, Karl?

https://cran.r-project.org/web/packages/reprex/README.html

On Fri, 17 Mar 2017, Bert Gunter wrote:

> You are wrong. No reordering occurs.
>
> Cheers,
> Bert
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Fri, Mar 17, 2017 at 8:05 AM, Karl Schilling
> <[hidden email]> wrote:
>> Dear all:
>>
>> I have two data.frames A and B of the same number of rows (about 40,000). I
>> realized that when I copy column x from data.frame A to B, the order of this
>> column  gets changed. This seems to affect only values in rownumbers > ~
>> 35/36,000. It also happens in any of the following three approaches:
>>
>> A$x <- B$x
>>
>> x <- B$x (here, x is still in the correct order)
>> B$x <- x : now x is reordered
>>
>> B <- cbind(A, B$x)
>>
>> I am working with Windows7Pro/64bit, R 3.3.3, and RStudio 0.99.903.
>>
>> Any help would be appreciated.
>>
>> Best regards
>>
>> Karl Schilling
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
                                       Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: inadverted reordering of a df column when it is copied to another df

Rui Barradas
Hello,

Not an answer to the OP's statement, but

 > class(1L:40000L)
[1] "integer"
 > class(1:40000)
[1] "integer"

When using m:n there's no need for mL  or nL.

Rui Barradas

Em 17-03-2017 16:58, Jeff Newmiller escreveu:

> Reprex confirming Bert:
>
> A <- data.frame( y = 1L:40000L )
> B <- data.frame( x = 1L:40000L )
> A$x <- B$x
> plot(B$x)
>
> #' ![](http://i.imgur.com/cXSFsBh.png)
>
> Care to demonstrate for us, Karl?
>
> https://cran.r-project.org/web/packages/reprex/README.html
>
> On Fri, 17 Mar 2017, Bert Gunter wrote:
>
>> You are wrong. No reordering occurs.
>>
>> Cheers,
>> Bert
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along
>> and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>>
>> On Fri, Mar 17, 2017 at 8:05 AM, Karl Schilling
>> <[hidden email]> wrote:
>>> Dear all:
>>>
>>> I have two data.frames A and B of the same number of rows (about
>>> 40,000). I
>>> realized that when I copy column x from data.frame A to B, the order
>>> of this
>>> column  gets changed. This seems to affect only values in rownumbers > ~
>>> 35/36,000. It also happens in any of the following three approaches:
>>>
>>> A$x <- B$x
>>>
>>> x <- B$x (here, x is still in the correct order)
>>> B$x <- x : now x is reordered
>>>
>>> B <- cbind(A, B$x)
>>>
>>> I am working with Windows7Pro/64bit, R 3.3.3, and RStudio 0.99.903.
>>>
>>> Any help would be appreciated.
>>>
>>> Best regards
>>>
>>> Karl Schilling
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ---------------------------------------------------------------------------
> Jeff Newmiller                        The     .....       .....  Go Live...
> DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
>                                        Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
> /Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: inadverted reordering of a df column when it is copied to another df

R help mailing list-2
But note that m:n does not always produce an integer sequence.  It does when
the output can be accurately represented as an integer sequence, it
does not care
if the inputs were integer or numeric.
  > class( (2^31-10):(2^31-2) )
  [1] "integer"
  > class( (2^31-10):(2^31) ) # biggest integer is as.integer(2^31-1)
  [1] "numeric"
  > str(1.7:3.7)
   num [1:3] 1.7 2.7 3.7
  > str(1.0:3.0)
   int [1:3] 1 2 3
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Mar 17, 2017 at 10:53 AM, Rui Barradas <[hidden email]> wrote:

> Hello,
>
> Not an answer to the OP's statement, but
>
>> class(1L:40000L)
> [1] "integer"
>> class(1:40000)
> [1] "integer"
>
> When using m:n there's no need for mL  or nL.
>
> Rui Barradas
>
> Em 17-03-2017 16:58, Jeff Newmiller escreveu:
>>
>> Reprex confirming Bert:
>>
>> A <- data.frame( y = 1L:40000L )
>> B <- data.frame( x = 1L:40000L )
>> A$x <- B$x
>> plot(B$x)
>>
>> #' ![](http://i.imgur.com/cXSFsBh.png)
>>
>> Care to demonstrate for us, Karl?
>>
>> https://cran.r-project.org/web/packages/reprex/README.html
>>
>> On Fri, 17 Mar 2017, Bert Gunter wrote:
>>
>>> You are wrong. No reordering occurs.
>>>
>>> Cheers,
>>> Bert
>>>
>>> Bert Gunter
>>>
>>> "The trouble with having an open mind is that people keep coming along
>>> and sticking things into it."
>>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>>
>>>
>>> On Fri, Mar 17, 2017 at 8:05 AM, Karl Schilling
>>> <[hidden email]> wrote:
>>>>
>>>> Dear all:
>>>>
>>>> I have two data.frames A and B of the same number of rows (about
>>>> 40,000). I
>>>> realized that when I copy column x from data.frame A to B, the order
>>>> of this
>>>> column  gets changed. This seems to affect only values in rownumbers > ~
>>>> 35/36,000. It also happens in any of the following three approaches:
>>>>
>>>> A$x <- B$x
>>>>
>>>> x <- B$x (here, x is still in the correct order)
>>>> B$x <- x : now x is reordered
>>>>
>>>> B <- cbind(A, B$x)
>>>>
>>>> I am working with Windows7Pro/64bit, R 3.3.3, and RStudio 0.99.903.
>>>>
>>>> Any help would be appreciated.
>>>>
>>>> Best regards
>>>>
>>>> Karl Schilling
>>>>
>>>> ______________________________________________
>>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>>> PLEASE do read the posting guide
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>>> ______________________________________________
>>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>> ---------------------------------------------------------------------------
>> Jeff Newmiller                        The     .....       .....  Go
>> Live...
>> DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live
>> Go...
>>                                        Live:   OO#.. Dead: OO#..  Playing
>> Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
>> /Software/Embedded Controllers)               .OO#.       .OO#.
>> rocks...1k
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

SOLVED: inadverted reordering of a df column when it is copied to another df

karl.schilling
In reply to this post by karl.schilling

Dear All:

it seems I have solved my reordering issue, and to thank all those who
answered, I briefly list the mistake I made.

I stared out from some data.frame holding values x and a grouping
factor. Actually, my factor was a number (but not numeric) which was,
however, not ordered. So it would go something like 1 1 1 2 2 2 4 4 4 3 3 3.

Then I performed some calculation on subsets of x defined by this factor
using by(x, factor, function).

I then converted the result from the list obtained to a data.frame, and
from this data.frame I copied one column into my original data.frame.
The point I apparently missed was that the list obtained using "by", was
ordered based on the factor (i.e. 1,1,1,2,2,2,3,3,3,4,4,4), and the same
was true for the df I generated from this list.

Thank you for all your input

Karl



On 17.03.2017 16:16, Thierry Onkelinx wrote:
 > Dear Karl,
 >
 > This is hard to investigate without a reproducible example.
 >
 > Best regards,
 > ir. Thierry Onkelinx
 > Instituut voor natuur- en bosonderzoek / Research Institute for Nature
 > and Forest
 > team Biometrie & Kwaliteitszorg / team Biometrics & Quality Assurance
 > Kliniekstraat 25
 > 1070 Anderlecht
 > Belgium
 >
 > To call in the statistician after the experiment is done may be no
 > more than asking him to perform a post-mortem examination: he may be
 > able to say what the experiment died of. ~ Sir Ronald Aylmer Fisher
 > The plural of anecdote is not data. ~ Roger Brinner
 > The combination of some data and an aching desire for an answer does
 > not ensure that a reasonable answer can be extracted from a given body
 > of data. ~ John Tukey
 >
 >
 > 2017-03-17 16:05 GMT+01:00 Karl Schilling <[hidden email]>:
 >> Dear all:
 >>
 >> I have two data.frames A and B of the same number of rows (about
40,000). I
 >> realized that when I copy column x from data.frame A to B, the order
of this
 >> column  gets changed. This seems to affect only values in rownumbers > ~
 >> 35/36,000. It also happens in any of the following three approaches:
 >>
 >> A$x <- B$x
 >>
 >> x <- B$x (here, x is still in the correct order)
 >> B$x <- x : now x is reordered
 >>
 >> B <- cbind(A, B$x)
 >>
 >> I am working with Windows7Pro/64bit, R 3.3.3, and RStudio 0.99.903.
 >>
 >> Any help would be appreciated.
 >>
 >> Best regards
 >>
 >> Karl Schilling
 >>
 >> ______________________________________________
 >> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
 >> https://stat.ethz.ch/mailman/listinfo/r-help
 >> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
 >> and provide commented, minimal, self-contained, reproducible code.


-

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Loading...