I am trying to use the subset function to pick out certain lines of a data frame which contain the symbols * or +. I would like to put these entire lines of my data frame into a new data frame. I think that subset will be the best way to do this.
Below is my attempt:
nba <- read.csv('nba.csv',header=FALSE)
nba
two <- grep('\\Q*\\E',nba$V2)
one <- grep('\\Q+\\E',nba$V2)
both <- c(one,two)
allstar <- subset.data.frame(nba, both)
subset
takes logical values for subset
argument. Use grepl
("l" for "logical") instead:
two <- grepl('\\Q*\\E',nba$V2)
one <- grepl('\\Q+\\E',nba$V2)
both <- one | two ## logical "or" operation
allstar <- subset.data.frame(nba, both)
Note, two
, one
and both
have length nrow(nba)
.