I have a variable which is used after it has been formed using paste
. However after pasting the variable comes insider quotes which makes it unusable. This variable is inside as.date
so as.name
is not working. noquotes
is not working as well. Is there any other way this variable can be used in as.date
quotes free?
An example:
names<-c("dateA","dateB")
dateA<-c("5/30/2014","6/01/2014")
dateB<-c("5/30/2014")
dateZ<-as.data.frame(c("5/30/2014","6/01/2014","6/02/2014"))
names(dateZ)<-"date"
dateZ$date <- as.Date(dateZ$date,"%m/%d/%Y")
for (item in names){
dateZ[paste(item)] <- ifelse(dateZ$date %in% as.Date(paste(item), format = "%m/%d/%Y"), 1, 0)
}
The output is
> dateZ
date dateA dateB
1 2014-05-30 0 0
2 2014-06-01 0 0
3 2014-06-02 0 0
However the output I want is
date dateA dateB
1 2014-05-30 1 1
2 2014-06-01 1 0
3 2014-06-02 0 0
I suspect it is due to the quotes which are staying back because of paste(items). Simply using item yields the same result.
Thanks in advance and sorry for not providing an example before