Remove entries containing a specific character

#1
I'm a bit of an R newb, and this is my first post on these forums, so sorry if the answer to this question is obvious! Say this is my data frame:

Code:
mydata <- structure(list(names = structure(c(1L, 5L, 2L, 3L, 4L), .Label = c("bob", 
"craig@gmail.com", "emily", "jane@yahoo.com", "joe"), class = "factor"), 
    emails = structure(c(1L, 5L, 2L, 3L, 4L), .Label = c("bobj@cup.com", 
    "craig@gmail.com", "emily2@yahoo.com", "jane@yahoo.com", 
    "joesmith@gmail.com"), class = "factor")), .Names = c("names", 
"emails"), row.names = c(NA, -5L), class = "data.frame")
Which produces:

Code:
            names             emails
1             bob       bobj@cup.com
2             joe joesmith@gmail.com
3 craig@gmail.com    craig@gmail.com
4           emily   emily2@yahoo.com
5  jane@yahoo.com     jane@yahoo.com
I want to delete all entries in mydata$names that contain an @ character, so that my data frame becomes:

Code:
  names             emails
1   bob       bobj@cup.com
2   joe joesmith@gmail.com
3          craig@gmail.com
4 emily   emily2@yahoo.com
5           jane@yahoo.com
How would I go about this? Alternately, if I wanted to delete the entire row, not just the entries, how would I do that? In this case my data frame would become:

Code:
  names             emails
1   bob       bobj@cup.com
2   joe joesmith@gmail.com
3 emily   emily2@yahoo.com

Thanks so much for any help, and sorry again if this is an overly simple question!
 

trinker

ggplot2orBust
#3
First off your columns are stored as factors not character. Factors don't make sense really so I changed the class of names to character:

Code:
mydata <- structure(list(names = structure(c(1L, 5L, 2L, 3L, 4L), .Label = c("bob", 
   "craig@gmail.com", "emily", "jane@yahoo.com", "joe"), [COLOR="red"]class = "factor"[/COLOR]), 
    emails = structure(c(1L, 5L, 2L, 3L, 4L), .Label = c("bobj@cup.com", 
    "craig@gmail.com", "emily2@yahoo.com", "jane@yahoo.com", 
    "joesmith@gmail.com"), [COLOR="red"]class = "factor"[/COLOR])), .Names = c("names", 
    "emails"), row.names = c(NA, -5L), class = "data.frame")
Code:
mydata$names <- as.character(mydata$names)

cont <- grepl("@", mydata$names)

mydata$names[cont] <- ""
mydata

mydata[!cont, ]
the grepl is what searchers for a character (in this case @) and returns a logical vector of yes it contains this character or no it does not (that's the cont string I made).