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, ]) ?

1
  • 2
    You can use == i.e. e[e$Equipe == "Montréal",] Commented Oct 23, 2022 at 18:09

1 Answer 1

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") 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.