[R] A logical comparison between two character strings in R
Dear All, Does anyone know how to compare two character strings in R? For eample, how to compare A-1-B with cc-1 in logical ? Cheers, Lun Li __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] A logical comparison between two character strings in R
Lun Li [EMAIL PROTECTED] writes: Dear All, Does anyone know how to compare two character strings in R? For eample, how to compare A-1-B with cc-1 in logical ? Ehhh... Is it this that you want? A-1-B == cc-1 [1] FALSE A-1-B = cc-1 [1] TRUE A-1-B cc-1 [1] FALSE d-1-B cc-1 [1] TRUE -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
[R] A logical comparison between two character strings in R
Dear All, Can anyone know how to compare two character strings in R? For eample, how to compare A-1-B with cc-1 in logical ? Cheers, Lun Li __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] A logical comparison between two character strings in R
Lun Li [EMAIL PROTECTED] writes: Thanks. But, my question is: pro.name[1] V1 1 B-29BT3 temp.name[1] V1 1 A-1H if(tem.name[1]==pro.name[1]){cat(ok)} Error in Ops.factor(left, right) : Level sets of factors are different How to compare them? Then they are factors, not character variables. Use as.character on both sides. -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] A logical comparison between two character strings in R
Thanks. But, my question is: pro.name[1] V1 1 B-29BT3 temp.name[1] V1 1 A-1H if(tem.name[1]==pro.name[1]){cat(ok)} Error in Ops.factor(left, right) : Level sets of factors are different How to compare them? Lun Quoting Peter Dalgaard BSA [EMAIL PROTECTED]: Lun Li [EMAIL PROTECTED] writes: Dear All, Does anyone know how to compare two character strings in R? For eample, how to compare A-1-B with cc-1 in logical ? Ehhh... Is it this that you want? A-1-B == cc-1 [1] FALSE A-1-B = cc-1 [1] TRUE A-1-B cc-1 [1] FALSE d-1-B cc-1 [1] TRUE -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] A logical comparison between two character strings in R
On 21 Aug 2003 at 15:49, Lun Li wrote: Thanks. But, my question is: pro.name[1] V1 1 B-29BT3 temp.name[1] V1 1 A-1H if(tem.name[1]==pro.name[1]){cat(ok)} Error in Ops.factor(left, right) : Level sets of factors are different I suppose your variables are actually factors not characer vectors. see temp.name [1] B-29BT3 ccc-29BT3 Levels: B-29BT3 ccc-29BT3 pro.name [1] B-29BT3 B-29BT3 Levels: B-29BT3 if(temp.name[1]==pro.name[1]){cat(ok)} Error in Ops.factor(temp.name[1], pro.name[1]) : Level sets of factors are different but pro.name.ch [1] B-29BT3 B-29BT3 temp.name.ch [1] B-29BT3 ccc-29BT3 if(temp.name.ch[1]==pro.name.ch[1]){cat(ok)} ok How to compare them? make them character, see ?as.character Lun Quoting Peter Dalgaard BSA [EMAIL PROTECTED]: Lun Li [EMAIL PROTECTED] writes: Dear All, Does anyone know how to compare two character strings in R? For eample, how to compare A-1-B with cc-1 in logical ? Ehhh... Is it this that you want? A-1-B == cc-1 [1] FALSE A-1-B = cc-1 [1] TRUE A-1-B cc-1 [1] FALSE d-1-B cc-1 [1] TRUE -- O__ Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907 __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help Petr Pikal [EMAIL PROTECTED] __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help
Re: [R] A logical comparison between two character strings in R
Did you check any documentation on R, e.g., help(Comparison) or www.r-project.org - Manuals - An Introdunction to R? In Section 2.4 on Logical vectors, I find, The logical operators are , =, , =, == for exact equality ... . Consider the following: A-1-B == cc-1 [1] FALSE hope this helps. spencer graves Lun Li wrote: Dear All, Does anyone know how to compare two character strings in R? For eample, how to compare A-1-B with cc-1 in logical ? Cheers, Lun Li __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help __ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help