The `rownames()` method in R is used to rename and replace the row names of a matrix-like object (incl. data frames) .
Questions tagged [r-rownames]
113 questions
2
votes
1 answer
How to get the row's name from row number?
I wonder how I can extract the row name from row number?
x <- data.frame( A = 1:10, B = 21:30 )
rownames( x ) <- sample( LETTERS, 10 )
> x
A B
J 1 21
A 2 22
I 3 23
G 4 24
H 5 25
B 6 26
P 7 27
Z 8 28
O 9 29
R 10 30
> x[ "H",]
A B
H…

Cina
- 9,759
- 4
- 20
- 36
1
vote
2 answers
Saving CSV files as tab delimited files while keeping the row names
I have a folder that is full of CSV files. Each file has genes as row names and samples as columns. I need them as TSV, so I saved each one of them as TSV and into a new path. This is the code:
folder_path <- "/original/folder/path"
csv_files <-…

Programming Noob
- 1,232
- 3
- 14
1
vote
1 answer
Turn a data frame column into vector with names as row names
I have an output which looks like the following code:
data.frame(H = c(1.5,4.5,5,8)) %>% `rownames<-`(c("a","b","c","d"))
H
a 1.5
b 4.5
c 5.0
d 8.0
Ideally, using dplyr, I would like to convert it to a vector like this:
a b c d
1.5 4.5…

Abbas
- 807
- 7
- 14
1
vote
1 answer
change rownames in a list of data.frames using a master data.frame
I have a bunch of lists, and I want to rename the rows using a master data.frame.
Here's an example list I created:
df <- data.frame(Value = c(1, 0, 6, 3, 4))
rownames(df) <- c("B144","B211","B678","B111", "B7090")
df2 <- data.frame(Value = c(0, 0,…

E Norton
- 83
- 4
1
vote
1 answer
Eliminating row.names from a data.frame
I have a data frame named AE, typically I set the row names to NULL to allow an rbind. In this cases when I do that, the row.names are still "1","2", and do not allow a bind. I am not understanding what is different about this data.frame.
#load…

MatthewR
- 2,660
- 5
- 26
- 37
1
vote
0 answers
R pheatmap: How to color specific row names while omitting column names?
Using the "pheatmap" package in R, with Rstudio for Windows 10, I can follow an example(as shown here) to produce a heatmap with selective coloring of row names as long as the heatmap displays both row and column names. However, if I try to generate…

Hypersphere
- 11
- 1
1
vote
1 answer
How do I assign row names to numeric matrix so they can be displayed on a heatmap?
So I'm trying to create a Heatmap using ComplexHeatmap package and my data has first column as a species name, e.g. "Shigella" and the next 8 columns titled by their sample id represent how many times each species were observed(as a numeric value)…

Michael
- 11
- 2
1
vote
2 answers
Rearrange rownames of data.frame (non alphabetic)
set0 <- data.frame(A = c("A", "B", "C", "D", "A", "B", "C", "D", "A", "B"),
B = c("E", "F", "G", "H", "I", "E", "F", "G", "H", "I"))
set0 <- table(set0)
result:
> set0
B
A E F G H I
A 1 0 0 1 1
B 1 1 0 0 1
C 0 1 1 0…

Robbie Voort
- 121
- 6
1
vote
1 answer
How can I delete the rownames which contain specific text in R?
I would like to remove the rownames ONLY of the rows which contain "Apple_"
df <- data.frame('fruit'=c("Apple_1", "Apple_2", "Apple_3", "Pear_1", "Pear_2", "Pear_3"),
'color'=c("Red", "Red", "Green","Green","Green","Green"))
df<-…

Ecg
- 908
- 1
- 10
- 28
1
vote
1 answer
Why does as_tibble(mtcars,rownames = NA) not show the row names? The documentation says that it should
mtcars clearly has row names:
> 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 110 3.90 2.875 17.02 0 1 4 …

J. Mini
- 1,868
- 1
- 9
- 38
1
vote
1 answer
100x loop, get rownames from dataframe A and add as a column to a new dataframe B each time, ending with 100 columns in B
I want to execute a 100x loop, get rownames from a dataframe A and add its rownames as values in a column to a new dataframe B each time, ending with 100 columns in B. I am beating my head against the wall here trying to do this, as I seem to…

Zoidberg_OuuuO
- 65
- 4
1
vote
2 answers
Rename rownames
I would like to rename row names by removing common part of a row name
a b c
CDA_Part 1 4 4
CDZ_Part 3 4 4
CDX_Part 1 4 4
result
a b c
CDA 1 4 4
CDZ 3 4 4
CDX 1 4 4

giegie
- 463
- 4
- 11
1
vote
2 answers
The first two columns defined as "rownames"
I want to define the first two columns of a data frame as rownames. Actually I want to do some calculations and the data frame has to be numeric for that.
data.frame <- data_frame(id=c("A1","B2"),name=c("julia","daniel"),BMI=c("20","49"))
The…

takeITeasy
- 350
- 3
- 19
1
vote
1 answer
First row as column names in a list of data frames(2)
I want to rename the columns of every data frame in my list of data frames with the first row.
I tried the code from this question First row as column names in a list of data frames
but it returns first_row_name=rows_number /c(date=3)/
dflist1 <-…

Mar
- 117
- 10
1
vote
1 answer
cannot change rownames of a table
I created this table:
> head(table)
tissue1 tissue2 tissue3 tissue4 tissue5
Simple_repeat_80 58 77 48 69 115 131
tRNA_1 0 14 12 1 19 …

jonny jeep
- 383
- 3
- 12