Hi All, I am trying to match two character arrays (email lists) using either pmatch(), match() or charmatch() functions. However the function is "missing" some matches due to differences in the cases of some letters between the two arrays. Is there any way to disable case sensitivity or is there an entirely better way to match two character arrays that have identical entries but written in different case? Thanks Nikita
On Tue, 26 Aug 2003, Jablonsky, Nikita wrote:> Hi All, > > I am trying to match two character arrays (email lists) using either > pmatch(), match() or charmatch() functions. However the function is > "missing" some matches due to differences in the cases of some letters > between the two arrays. Is there any way to disable case sensitivity or is > there an entirely better way to match two character arrays that have > identical entries but written in different case? >You could use tolower() or toupper() to remove case differences. -thomas
On Tue, 2003-08-26 at 15:09, Jablonsky, Nikita wrote:> Hi All, > > I am trying to match two character arrays (email lists) using either > pmatch(), match() or charmatch() functions. However the function is > "missing" some matches due to differences in the cases of some letters > between the two arrays. Is there any way to disable case sensitivity or is > there an entirely better way to match two character arrays that have > identical entries but written in different case? > > Thanks > NikitaAt least two options for case insensitive matching: 1. use grep(), which has an 'ignore.case' argument that you can set to TRUE. See ?grep 2. use the function toupper() to convert both character vectors to all upper case. See ?toupper. Conversely, tolower() would do the opposite. A quick solution using the second option would be: Vector1[toupper(Vector1) %in% toupper(Vector2)] which would return the elements that match in both vectors. A more formal example with some data: Vector1 <- letters[1:10] Vector1 [1] "a" "b" "c" "d" "e" "f" "g" "h" "i" "j" Vector2 <- c(toupper(letters[5:8]), letters[9:15]) Vector2 [1] "E" "F" "G" "H" "i" "j" "k" "l" "m" "n" "o" Vector1[toupper(Vector1) %in% toupper(Vector2)] [1] "e" "f" "g" "h" "i" "j" HTH, Marc Schwartz
Hallo On 26 Aug 2003 at 13:09, Jablonsky, Nikita wrote:> Hi All, > > I am trying to match two character arrays (email lists) using either > pmatch(), match() or charmatch() functions. However the function is > "missing" some matches due to differences in the cases of some letterstry toupper or tolower> ttt<-toupper("differences in the cases") > ttt[1] "DIFFERENCES IN THE CASES"> tolower(ttt)[1] "differences in the cases">> between the two arrays. Is there any way to disable case sensitivity > or is there an entirely better way to match two character arrays that > have identical entries but written in different case? > > Thanks > Nikita > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo/r-helpPetr Pikal petr.pikal at precheza.cz