How to subset a data frame by a rowvalue

There are no stupid questions on this forum; everyone of us either asking or reading any question has the potential to learn. Sok?

@phiggins has a workable suggestion in his post:


df <- data.frame(
  one = c(2,1,2),
  two = c(4,5,3),
  three = c(3,7,4)
row.names(df) <- c('a','b','c')
t(df) %>% %>% 
  filter(a >=3) %>% 
  t() %>% 

The resulting object df can first be assigned to its own name

df <- t(df)

Then you need to decide if you want a,b,c as rownames or a variable. If rownames, you're done; if a variable

df <- tibble::rownames_to_column(df)

To get more precise guidance, we still need some rows of your actual dataframe in a reproducible example, called a reprex,

1 Like