I am trying to rename rows in my dataset. I need to change them like this: first row would be named "IL1", second "IL2",..., "ILn", where n is a number of rows in the dataset. I know how to change it by for example rownames(df) <- c("IL1","IL2","IL3","IL4"). But type it word by word is possible only in smaller datasets. I need to change it in dataset where are hundreds of rows. Any ideas? Thank you.
Asked
Active
Viewed 32 times
1 Answers
1
You can use paste0
:
rownames(df) <- paste0("IL", 1:nrow(df))

Chris Ruehlemann
- 20,321
- 4
- 12
- 34
-
Thank you so much Chris! – ondrej Jan 03 '22 at 21:20
-
Thanks for this. Did you know you can also accept an answer by clicking the tick mark in the left upper corner? – Chris Ruehlemann Jan 04 '22 at 09:39