Moumita Das
2009-Jun-06 10:21 UTC
[R] how to make the dynamically creted string work inside if as a condition
Hi, How to make an if condition work, if the condition inside if() is created dynamically ,and that is a string .If i type teh dynamically created string the if works fine but when dynamically created,it is a string and going inside the if() ,an error is thrown saying : rgument is not logical ..I even tried changing teh mode of the string to logical,but it doesn't work Say my dynamically created string is :-- str<- name=='tom' || name=='harry' || name=='tina' where the names are diffrent for diffrent DBs. if(name=='tom' || name=='harry' || name=='tina' ) { some code } If i do this if(str) { some code } It doesn't work:( -- Thanks Moumita [[alternative HTML version deleted]]
Duncan Murdoch
2009-Jun-06 11:05 UTC
[R] how to make the dynamically creted string work inside if as a condition
Moumita Das wrote:> Hi, > How to make an if condition work, if the condition inside if() is created > dynamically ,and that is a string .If i type teh dynamically created string > the if works fine but when dynamically created,it is a string and going > inside the if() ,an error is thrown saying : rgument is not logical ..I even > tried changing teh mode of the string to logical,but it doesn't work > > Say my dynamically created string is :-- > > str<- name=='tom' || name=='harry' || name=='tina' > where the names are diffrent for diffrent DBs. >That's not a string, it will be evaluated to a logical TRUE or FALSE value.> if(name=='tom' || name=='harry' || name=='tina' ) > { > some code > } > > If i do this > if(str) > { > > some code > } > > It doesn't work:( >Those should be equivalent. I think you need to simplify your example and post real code for us to see the problem. Duncan Murdoch
Maybe Matching Threads
- Fwd: Cannot allocate a new database connection error
- How to dynamically generate lm() function arguments?
- Error: system is computationally singular: reciprocal condition number
- Added system Info:--Segmentation Fault occured while connecting to the database
- help in R