-1

In the following code below, i look over three variables in a dataset. However, I would like to look over the three variable when the year column is equal to 72. Is there a way to do it by using the View function?

library(plm)
data("Cigar")

View(Cigar[, c("year","price", "sales")])
Jack
  • 813
  • 4
  • 17

1 Answers1

1

You can do this in several ways. One way is to use subset() with select. You don't need to quote column names.

For example:

View(subset(Cigar, select = c(year, price, sales), year == 72))

In R version 4.1.0 or newer you can also use the |> pipe :

Cigar |> 
subset(Cigar, select = c(year, price, sales), year == 72) |> 
View()
Abdur Rohman
  • 2,691
  • 2
  • 7
  • 12