Skip to content

Instantly share code, notes, and snippets.

@yutannihilation
Created January 3, 2015 04:09
Show Gist options
  • Save yutannihilation/3e53c624227a9e6aa551 to your computer and use it in GitHub Desktop.
Save yutannihilation/3e53c624227a9e6aa551 to your computer and use it in GitHub Desktop.
rownames of data_frame in dplyr

data_frame()row.names

data_framedplyrdata.frame)がどうなってるのかと思ってヘルプを見ると、

  1. Never adds row.names.

と書いてあります。実際試してみると、row.namesを指定しても同名の列が加わるだけです。

> (a <- data_frame(x = 1:6, y = runif(6), row.names = letters[1:6]))
Source: local data frame [6 x 3]

  x          y row.names
1 1 0.42845545         a
2 2 0.09404538         b
3 3 0.25676771         c
4 4 0.46133445         d
5 5 0.98806141         e
6 6 0.69865993         f
> rownames(a)
[1] "1" "2" "3" "4" "5" "6"

rownames<-()rownameを加えることはできますが、表示はされないみたいです。(add_rownames()とかで使うことはできる)

> rownames(a) <- letters[1:6]
> rownames(a)
[1] "a" "b" "c" "d" "e" "f"
> a
Source: local data frame [6 x 3]

  x          y row.names
1 1 0.42845545         a
2 2 0.09404538         b
3 3 0.25676771         c
4 4 0.46133445         d
5 5 0.98806141         e
6 6 0.69865993         f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment