I want to compare two string elements in R. The `str()` function of the two elemets gives me:

```
> (str(announcmentDate))
 chr "24.08.2009"
NULL
> (str(totalReturnsOfCompanyData$Date))
 chr [1:3036] "01.01.2002" "02.01.2002" "03.01.2002" "04.01.2002" ...
NULL
> 

```

I tried:

```
> for (i in totalReturnsOfCompanyData$Date) {
+   if (totalReturnsOfCompanyData$Date[i]==announcmentDate[1]) {
+       
+       print("YUPIDUUUUUUUUUS")        
+   }
+ }
Error in if (totalReturnsOfCompanyData$Date[i] == announcmentDate[1]) { : 
  missing value where TRUE/FALSE needed

```

Why am I getting this error? Is there an `equal` function(like in java) in R to show that the strings are equal?

I appreciate your answer!

**UPDATE**

I am using a for loop because I need the index later to extract a subsample from the data.

When I try:

```
> for (i in totalReturnsOfCompanyData$Date) {
+   if (na.omit(totalReturnsOfCompanyData$Date[i])==announcmentDate[1]) {
+       
+   #   eventWindow120Before <-
+   #   eventWindow120After  <-
+       print("YUPIDUUUUUUUUUS")        
+   }
+ }
Error in if (na.omit(totalReturnsOfCompanyData$Date[i]) == announcmentDate[1]) { : 
  argument is of length zero

```

Why do I get this error?