Sunday, March 15, 2015

R: Renaming Row numbers (Identifiers)

Many a times in R you have a dataset for which R provides a default numerical representation for identifying the individual rows :

> myData <- cbind(x = 3, y = c(4:1, 2:5))
> myData
     x  y
[1,]  3  4
[2,]  3  3
[3,]  3  2
[4,]  3  1
[5,]  3  2
[6,]  3  3
[7,]  3  4
[8,]  3  5
If you want to rename the rows as per your needs, you can do so by running the following command:

> dimnames(myData)[[1]] <- letters[1:8]
> myData
   x y
a  3  4
b  3  3
c  3  2
d  3  1
e  3  2
f  3  3
g  3  4
h  3  5
Happy programming!

No comments:

Section 80C TMT 2023(PA) – Standard Deduction amounting to a maximum of Rs 8670 under IT rule

With the recently concluded Tax filing season (which if I may draw parallel to the Christmas holiday season enjoyed by one and all), Indians...