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
3
votes
2 answers
How can I get row names from the apply() function's output?
I'm learning R and have a tibble with some World Bank data. I used the apply() function in a slice of the columns and applied the standard deviation over the values, in this way: result <- apply(df[6:46],2,sd,na.rm=TRUE).
The result is an object…

Jorge Sanmarcos
- 101
- 7
3
votes
1 answer
Why do identical dataframes become different when changing rownames to the same?
I've come across a strange behavior when playing with some dataframes: when I create two identical dataframes a,b, then swap their rownames around, they don't come out as identical:
rm(list=ls())
a <- data.frame(a=c(1,2,3),b=c(2,3,4))
b <-…

NicE
- 21,165
- 3
- 51
- 68
3
votes
2 answers
how to delete the first n characters of rownames in a data frame?
I have a data-frame which looks like this:
date_tmp efficiency smb rmrf hml rmw cma Returns
2010-11-04.Stock1 2010-11-04 0.4469618 0.87430339 0.7337814 0.00000000 0 0.60769928…

Alex Bădoi
- 830
- 2
- 9
- 24
2
votes
3 answers
Get row names based on column values, R, multiple conditions
Using the sample data set mtcars
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 …

M3Lba
- 97
- 7
2
votes
2 answers
gather() remove the row names of my dataframe. how can I have this row names?
when I use tidyr's gather() function and manipulate my dataframe, I lose row names of prev. data frame.
this is output of my rstudio console
> DF <- as.data.frame((freethrows/Games), row.names = rownames(Games), col.names = colnames(Games))
>…

Reza Esmaeelzade
- 193
- 9
2
votes
1 answer
Is there a way to name column names or rownames?
, , RE
Midterm Final mean
A 81.9 75.1 78.5
B 78.3 69.2 73.8
C 79.6 74.4 77.0
mean 79.9 72.9 76.4
I'm trying to name the rows and columns so that "Subject" is above the rows "A,B,C, and mean", and "Exam" is above the…

redwoods
- 59
- 5
2
votes
1 answer
How to replace rownames of a list of dataframes with values from a list of character strings in R?
Let l be a list of two dataframes and n a list of character strings, wherein l and n both have two elements. Also, let the number of rows of each dataframe in l be equal to the length of the vector of character strings in n.
l <- list(data.frame(x =…

Dion Groothof
- 1,406
- 5
- 15
2
votes
4 answers
replace row names with defined vector in R
Is there a way that the row names can be substituted based on predefined vector in R, something like:
rownames(GV) <- c(beta1='Age', beta10='Female Gender')

SysEng
- 43
- 8
2
votes
2 answers
How to convert a column to row.names from a tibble
This is a sample (normally it is 15 x 17) from my dataset entrepreneur imported from Excel with read_excel:
structure(list(Factors = c("Competition", "Cultural Support", "Financing", "High Growth", "Human Capital"), `Baden-Württemberg` = c("0.71",…

Frank_Crunch
- 23
- 3
2
votes
4 answers
how to return row values of a column such that their corresponding value in another column are the smallest n values, in R
I have df below.
df<-cbind(c("LA", "NY", "Rome"),c(1,1,2),c(0,1,0),c(0,1,2),c(1,3,4))
[city] [c1] [c2] [c3] [sum]
[1,] "LA" "1" "0" "0" "1"
[2,] "NY" "1" "1" "1" "3"
[3,] "Rome" "2" "0" "2" "4"
I want to compare the values in…

Mathica
- 1,241
- 1
- 5
- 17
2
votes
2 answers
Set row names of matrices in an array
I have an array consisting many 2*3 matrices.
I want to give same row names to both rows of each matrix in my array. I'm trying dimnames(), however I'm not getting what I want.
c1a <- c("1a","1a","1a")
c1b <- c("1b","1b","1b")
c2a <-…

Mathica
- 1,241
- 1
- 5
- 17
2
votes
5 answers
Sum non-conformable matrices by rowname in r
I have two unequally sized matrices, here is a small sample (my real matrices are much larger):
s <- matrix(1:36, nrow = 6, ncol = 6, byrow=TRUE, dimnames = list(c("Afghanistan","Albania","Algeria","Argentina","Australia","Austria"),…

MoonS
- 117
- 7
2
votes
2 answers
chisquare test in r that keeps row names
I'm building an employee survey with two waves, and I want to make sure that each wave is balanced in terms of some demographic variables, such as ethnicity and gender. Here is a fictitious sample of the data:
library(tidyverse)
sample_data <-…

J.Sabree
- 2,280
- 19
- 48
2
votes
3 answers
Appending Characters to Row Names Based on Condition
I have a large data frame where I would like to append characters to row names based on a condition. I have the following example:
trees <- data.frame(char = c('flower', 'cone', 'flower', 'cone'), number = c(3, 3, 5, 6))
rownames(trees) <-…

Danny
- 101
- 1
- 8
2
votes
1 answer
Row names in tableGrob are cut off when using row.just = "left
Can anyone solve why the cutoff of row names occurs for me? It is independent of the length of the string wrap. Specifying row.just = "center" does not cut off the row names.
x <- data.frame(row.names=paste("Very very name goes in here somewhere yep…

Alex
- 971
- 4
- 15
- 28