Reputation:
I'm new to R and I'm having a hard time removing those with -NWT suffix in a subsetting function below:
I've tried three lines I've seen on the internet but is still no luck:
trades.am <- subset(trades.am, Series.Name != "-NWT")
trades.am[trades.am$C != "-NWT", ]
sub.trades.am<-trades.am[trades.am[,3] != "-NWT",]
hope you guys can help.
Regards,
Upvotes: 0
Views: 222
Reputation: 887223
Try:
trades.am[!grepl("-NWT$", trades.am$Series.Name),]
# Series.Name value
#5 Something 1.6133728
#6 Something 0.0356312
#9 Something 0.8817912
#11 Something 0.9657529
#15 Something 1.9355718
vec1 <- c("FXTN 10-41*", "FXTN 90-21", "FXTN*")
grepl("\\*$", vec1)
# [1] TRUE FALSE TRUE
vec1[!grepl("\\*$", vec1)]
#[1] "FXTN 90-21"
set.seed(42)
trades.am <- data.frame(Series.Name= sample(c("Something-NWT", "Something",
"Some-NWT"),15, replace=TRUE), value=rnorm(15))
Upvotes: 2