`[<-.data.frame` sets rownames incorrectly

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

`[<-.data.frame` sets rownames incorrectly

Hervé Pagès-2
Hi,

Here is another problem with data frame subsetting:

   > df <- data.frame(aa=1:3)
   > value <- data.frame(aa=11:12, row.names=c("A", "B"))

   > `[<-`(df, 4:5, , value=value)
     aa
   1  1
   2  2
   3  3
   A 11
   B 12

   > `[<-`(df, 5:4, , value=value)
     aa
   1  1
   2  2
   3  3
   B 12
   A 11

For this last result, the rownames of the 2 last rows should
be swapped.

H.

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: [hidden email]
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: `[<-.data.frame` sets rownames incorrectly

Hervé Pagès-2
On 11/21/2017 06:19 PM, Hervé Pagès wrote:

> Hi,
>
> Here is another problem with data frame subsetting:
>
>    > df <- data.frame(aa=1:3)
>    > value <- data.frame(aa=11:12, row.names=c("A", "B"))
>
>    > `[<-`(df, 4:5, , value=value)
>      aa
>    1  1
>    2  2
>    3  3
>    A 11
>    B 12
>
>    > `[<-`(df, 5:4, , value=value)
>      aa
>    1  1
>    2  2
>    3  3
>    B 12
>    A 11

This actually produces:

   > `[<-`(df, 5:4, , value=value)
     aa
   1  1
   2  2
   3  3
   A 12
   B 11

but should instead produce:

     aa
   1  1
   2  2
   3  3
   B 12
   A 11

sorry for the confusion.

H.

>
> For this last result, the rownames of the 2 last rows should
> be swapped.
>
> H.
>

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: [hidden email]
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel