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
0
votes
1 answer
Add a prefix and a suffix only to some of the rownames
I have this dataframe:
structure(list(Treatnent.state = c("PRE Immune Checkpoint Blockade Therapy",
"PRE Immune Checkpoint Blockade Therapy", "PRE Immune Checkpoint Blockade Therapy",
"PRE Immune Checkpoint Blockade Therapy", "PRE Immune…

Programming Noob
- 1,232
- 3
- 14
0
votes
1 answer
How do I change the tcga data barcode rowname?
My tcga data's barcode, row name, looks like this.
TCGA-4P-AA8J-01A-11D-A390-01
I want to change it to this form using a for loop.
-> TCGA.4P.AA8J.01A
r=c()
for (x in rownames(df)) {
r <-c(substr(gsub("-",".",x),1,16))
rownames(df)<-r
…

coding_beginner
- 1
- 1
0
votes
1 answer
How do I remove a row in a data frame without using a row number?
I would like to delete a row in my data frame by not using the row number but instead an identifier within the row itself. This is because in the future the dataframe will be updated with new data, and the row number will not be in the same place.…

Hayley Schmidman
- 11
- 1
0
votes
2 answers
Error in converting the first column as a rowname in R dataframe
I have the dataset like below,
exp.data <- structure(list(Fasta.headers = c(">O76070ups|SYUG_HUMAN_UPS Gamma-synuclein (Chain 1-127) - Homo sapiens (Human)",
">Q06830ups|PRDX1_HUMAN_UPS Peroxiredoxin 1 (Chain 2-199) - Homo sapiens (Human)",…

KABILAN
- 73
- 7
0
votes
3 answers
R - replace specific values in df with values from other df by matching row names
I have df1:
df1 <- data.frame(X1 = c(2,5,1,5,4,6),
X2 = c(1,4,2,5,2,9),
X3 = c(8,4,2,6,3,8))
rownames(df1) <- rownames(df1) <- c("a","b","c","d","e","f")
X1 X2 X3
a 2 1 8
b 5 4 4
c 1 2 2
d 5 5 6
e 4 2 …

fishermen1275
- 3
- 2
0
votes
2 answers
Create a new dataframe with rownames paste0 from text and sequence number
Hej,
This might have been reviewed before, plus my R skills are getting rusty, but I am trying to generate a new dataframe, where rownames will be generated from strings and effectif / sequence number from a two columns data frame.
To make more…

Ann Mo
- 1
0
votes
1 answer
Merge by rownames in data.table
I wanted to use this solution, two merge two data.tables by row name. It does however not work.
z <- matrix(c(0,0,1,1,0,0,1,1,0,0,0,0,1,0,1,1,0,1,1,1,1,0,0,0,"RND1","WDR", "PLAC8","TYBSA","GRA","TAF"), nrow=6,
…

Tom
- 2,173
- 1
- 17
- 44
0
votes
1 answer
Set values to 0 if rownames contains specific words in R
Consider the following data.frame in R:
df <- data.frame(Agriculture = c(2,7,2),
Fishery = c(1,4,7),
Industry = c(5,7,3))
rownames(df) <- t(colnames(df))
If the rownames is "Fishery" or "Industry", I want…

Michael
- 565
- 4
- 11
0
votes
2 answers
rownames on multiple dataframe with for loop in R
I have several dataframe. I want the first column to be the name of each row.
I can do it for 1 dataframe this way :
# Rename the row according the value in the 1st column
row.names(df1) <- df1[,1]
# Remove the 1st column
df1 <- df1[,-1]
But I…
0
votes
1 answer
Keeping rownames when using setDT()
I have a data frame where:
df <- data.frame(row_id = c(100, 101, 102, 103, 104, 105, 106, 107, 108, 109),
row_id2 = c(1000,2000,3000,4000,5000,6000,7000,8000,9000,10000),
col1 = c(1,0,1,1,1,0,0,1,1,0),
col2 = c(1,1,1,0,0,1,1,1,0,0),
…

user1490
- 163
- 5
0
votes
1 answer
omu_anova error: row names supplied are of the wrong length
I am attempting to use the omu_anova function in the omu package for a set of metabolomics data. My code is the following,
metab_anova <- omu_anova(count_data = metab9, metadata = metabmeta4,
response_variable =…

salv
- 3
- 3
0
votes
1 answer
head output include row name not the row number
working through an assignment problem, very tired brain right now, could someone nudge me in the right direction please?
I have sorted a dataframe and I have organised what I want - the value of the country with the highest kidnapping rate. I have…

iKcon
- 71
- 7
0
votes
1 answer
Remove NAs from non-selected rownames in pheatmap in R
I have a selected group of genes I would like to plot which I have renamed. But when plotting them I also get the NAs for the non-selected. How could I remove the NAs only plotting my selected genes?
library(pheatmap)
set.seed(2020)
mat =…

Ecg
- 908
- 1
- 10
- 28
0
votes
2 answers
cut data frame using grep in row names
I have this data frame and I'm trying to create a new data frame from the first column.
> dput(test)
structure(list(r = structure(c(1, -0.242175528061635, -0.0666583192103071,
0.747898462006041, -0.273127322801604, -0.854174676122907,…

Johnny5ish
- 295
- 1
- 2
- 12
0
votes
2 answers
problem in setting one column as row id and then removing it
I have a simple problem but I just don't know how to fix it. I have a dataframe like this:
structure(list(ID = c(1006332, 1010660,
1012960, 1013515, 1014490), ave_ocean = c(1, 0, 0, 0, 0), ave_price_per_sqft = c(1419.69,
912.18, 600.74, 673.8725,…

Ross_you
- 881
- 5
- 22