-4

I have a data set containing some information about certain US states. The row names are states' names.

enter image description here

I want to select several states' (i.e. "AL" and "CA") information and create a new data set, but how?

Steve Ladavich
  • 3,472
  • 20
  • 27
Irene
  • 1
  • 1
  • 2
  • 1
    You can use `which` in R, or you can use the method here: http://stackoverflow.com/questions/7576138/how-to-remove-rows-of-a-matrix-by-row-name-rather-than-numerical-index – akash87 Jun 18 '16 at 04:25

2 Answers2

2

Well, you can form a vector of rownames

x <- c("AL", "CA" )

and then

df[x, ]

or directly

df[c("AL", "CA"), ]
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213
1
df2 <- df[rownames(df) %in% c("AL", "CA"),]
milan
  • 4,782
  • 2
  • 21
  • 39