Questions tagged [r-rownames]

The `rownames()` method in R is used to rename and replace the row names of a matrix-like object (incl. data frames) .

113 questions
227
votes
9 answers

How can I convert row names into the first column?

I have a data frame like this: df VALUE ABS_CALL DETECTION P-VALUE 1007_s_at "957.729231881542" "P" "0.00486279317241156" 1053_at "320.632701283368" "P" "0.0313356324173416" 117_at …
Agaz Wani
  • 5,514
  • 8
  • 42
  • 62
53
votes
4 answers

Row names & column names in R

Do the following function pairs generate exactly the same results? Pair 1) names() & colnames() Pair 2) rownames() & row.names()
Mehper C. Palavuzlar
  • 10,089
  • 23
  • 56
  • 69
36
votes
3 answers

How to remove rows of a matrix by row name, rather than numerical index?

I have matrix g: > g[1:5,1:5] rs7510853 rs10154488 rs12159982 rs2844887 rs2844888 NA06985 "CC" "CC" "CC" "CC" "CC" NA06991 "CC" "CC" "CC" "CC" "CC" NA06993 "CC" "CC" "CC" …
JoshDG
  • 3,871
  • 10
  • 51
  • 85
36
votes
4 answers

How can I merge more than 2 dataframes in R by rownames?

I gather data from 4 df's and would like to merge them by rownames. I am looking for an efficient way to do this. This is a simplified version of the data I have. df1 <- data.frame(N= sample(seq(9, 27, 0.5), 40, replace= T), …
Hans Roelofsen
  • 741
  • 1
  • 7
  • 13
20
votes
1 answer

How can I merge many data frames from csv files when the ID column is implied?

I'd like to merge a bunch of data frames together (because it seems many operations are easier if you're only dealing w/ one, but correct me if I'm wrong). Currently I have one data frame like this: ID, var1, var2 A, 2, 2 B, 4, 5 . . Z, 3, …
Peter
  • 1,155
  • 8
  • 20
17
votes
4 answers

Why do "subset" and "[" on a dataframe give slightly different results?

Could someone explain me why I get different results in my last two lines of code (identical() calls) below? These two objects seem to be identical objects, but when I use them in an apply function, I get some trouble: df <- data.frame(a = 1:5, b =…
mbh86
  • 6,078
  • 3
  • 18
  • 31
16
votes
1 answer

How do I extract rownames from a matrix?

I have a matrix with rownames that are dates. I want to extract these row names into a variable, and then use rownames() to apply these dates to another matrix I have. Let's say the matrix is called 'data.matrix'. Whenever I run: data.matrix[,0] I…
user1613119
  • 225
  • 2
  • 3
  • 9
13
votes
1 answer

How can I remove rownames in gridExtra::tableGrob?

I would like to plot a table with ggplot, however, I cannot seem to manage to lose the row.names. I have tried: row.names(cov_table_a)<-NULL # outside the plot row.names = FALSE # inside the annotation_custom This is my…
T. BruceLee
  • 501
  • 4
  • 16
12
votes
4 answers

What is the first column in R's mtcars dataset?

I think I am missing a fundamental concept about R's data frames. head(mtcars) mpg cyl disp hp drat wt qsec vs am gear carb Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 Mazda RX4 Wag 21.0 6 160…
buhtz
  • 10,774
  • 18
  • 76
  • 149
11
votes
3 answers

How can I subscript names in a table from kable()?

Given a data.frame A, how can I use subscripted rows and columns names? Eventually I want produce a table through kable() in rmarkdown (output: word document). A <- data.frame(round(replicate(3, runif(2)),2)) rownames(A) <- c("Hola123",…
AJMA
  • 1,134
  • 2
  • 13
  • 28
11
votes
1 answer

How can I convert row names in multiple data frames to column in data frame>

I have a list of .csv files that I have read in to R and placed in a large data frame called data that consists of 6 data.frames which are the 6 files in filenames. My code so far is: filenames <- list.files( paste(mainDirInput,sep=""),…
userk
  • 901
  • 5
  • 11
  • 19
9
votes
2 answers

R returning partial matching of row names

I've run into the following issue vec <- c("a11","b21","c31") df <- data.frame(a = c(0,0,0), b = c(1,1,1), row.names = vec) df["a",] returns df["a",] a b a11 0 1 However, "a" %in% vec and "a" %in% rownames(df) both return False R is…
Lauren Cote
  • 91
  • 1
  • 2
8
votes
1 answer

How can I keep rownames when converting a matrix into a data frame?

I want to convert a matrix to a data frame. When I use df <- mat %>% data.frame() , I lose the rownames. How do I keep them?
user42485
  • 751
  • 2
  • 9
  • 19
7
votes
1 answer

Why does R have inconsistent behaviors when a non-existent rowname is retrieved from a data frame?

I wonder why two data frames a and b have different outcomes when a non-existent rowname is retrieved. For example, a <- as.data.frame(matrix(1:3, ncol = 1, nrow = 3, dimnames = list(c("A1", "A10", "B"), "V1"))) a V1 A1 1 A10 2 B 3 b <-…
foehn
  • 431
  • 4
  • 13
7
votes
3 answers

How can I Change dimnames of matrices and data frames in R

Let's say I have created the following matrix: > x <- matrix(1:20000,nrow=100) > x[1:10,1:10] [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 101 201 301 401 501 601 701 801 901 [2,] 2 102 202 302 402 502 602 …
Mehper C. Palavuzlar
  • 10,089
  • 23
  • 56
  • 69
1
2 3 4 5 6 7 8