1

I have this data.frame:

e=data.frame(Equipe = c("Washington","Dallas","Chicago","Los Angeles", "St-Louis", "Detroit", "Montréal", "Boston"),
MJ = c(55,56,57,58,56,57,56,57),
V = c(36,32,30,30,25,25,22,24),
D = c(16,19,21,22,19,21,27,31),
DP = c(3,5,6,6,12,11,7,2),
PTS = c(75,69,66,66,62,61,51,50))

and the output is like so:

Data Frame

How do I print the "Montreal" entire row (not using e[7, ]) ?

user438383
  • 5,716
  • 8
  • 28
  • 43

1 Answers1

0

There are multiple ways to do so.

The first in base R upon the valuable @akrun comment:

e[e$Equipe == "Montréal",]

The second with dplyr package (needs to be installed - use install.packages("dplyr") for this) :

library(dplyr) 
e %>% filter(Equipe == "Montréal")

The third with data.table package (also needs to be installed) :

library(data.table)
DT <- data.table(e)
DT[e$Equipe == "Montréal"]

The combination of the second and the third with a bit advanced base R:

library(data.table)
library(dplyr)
e %>%
data.table() %>%
'['(e$Equipe == "Montréal") 
asd-tm
  • 3,381
  • 2
  • 24
  • 41