Skip to content

Instantly share code, notes, and snippets.

@kirillseva
Created June 13, 2016 22:06
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kirillseva/46a798623ebd2140421949360afc1d66 to your computer and use it in GitHub Desktop.
Save kirillseva/46a798623ebd2140421949360afc1d66 to your computer and use it in GitHub Desktop.
I hate rownames
R-STABLE> a <- data.frame(a=1:5, b=head(letters, 5))
R-STABLE> a
a b
1 1 a
2 2 b
3 3 c
4 4 d
5 5 e
R-STABLE> b <- a[c(1,3,5),]
R-STABLE> b
a b
1 1 a
3 3 c
5 5 e
R-STABLE> str(b)
'data.frame': 3 obs. of 2 variables:
$ a: int 1 3 5
$ b: chr "a" "c" "e"
R-STABLE> rownames(b)
[1] "1" "3" "5"
R-STABLE> dput(b)
structure(list(a = c(1L, 3L, 5L), b = c("a", "c", "e")), .Names = c("a",
"b"), row.names = c(1L, 3L, 5L), class = "data.frame")
R-STABLE> b[2,]
a b
3 3 c
R-STABLE> b[3,]
a b
5 5 e
R-STABLE> b["3",]
a b
3 3 c
R-STABLE> b["2",]
a b
NA NA <NA>
R-STABLE>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment