Re: [R] character comp

2019-02-09 Thread Val
Thank you Erin and Rui! On Sat, Feb 9, 2019 at 1:08 PM Erin Hodgess wrote: > > Nice, Rui! Thanks > > On Sat, Feb 9, 2019 at 11:55 AM Rui Barradas wrote: >> >> Hello, >> >> The following will do it. >> >> mydataframe$dvar <- c(sapply(mydataframe[-1], nchar) %*% c(1, -1)) >> >> >> Hope this help

Re: [R] character comp

2019-02-09 Thread Rui Barradas
After correcting the typo I tested both and yours is over twice as fast as mine. Rui Barradas Às 19:08 de 09/02/2019, Erin Hodgess escreveu: Nice, Rui!  Thanks On Sat, Feb 9, 2019 at 11:55 AM Rui Barradas > wrote: Hello, The following will do it. m

Re: [R] character comp

2019-02-09 Thread Erin Hodgess
Nice, Rui! Thanks On Sat, Feb 9, 2019 at 11:55 AM Rui Barradas wrote: > Hello, > > The following will do it. > > mydataframe$dvar <- c(sapply(mydataframe[-1], nchar) %*% c(1, -1)) > > > Hope this helps, > > Rui Barradas > > Às 18:05 de 09/02/2019, Val escreveu: > > Hi All, > > In a given data

Re: [R] character comp

2019-02-09 Thread Rui Barradas
Hello, It should be nchar(mydataframe[,2])-nchar(mydataframe[,3]) since the first column is ID. Hope this helps, Rui Barradas Às 18:31 de 09/02/2019, Erin Hodgess escreveu: Ok. Try something like nchar(mydataframe[,1])-nchar(mydataframe[,2]) On Sat, Feb 9, 2019 at 11:21 AM Erin Hodgess

Re: [R] character comp

2019-02-09 Thread Rui Barradas
Hello, The following will do it. mydataframe$dvar <- c(sapply(mydataframe[-1], nchar) %*% c(1, -1)) Hope this helps, Rui Barradas Às 18:05 de 09/02/2019, Val escreveu: Hi All, In a given data frame I want to compare character values of two columns. My sample data looks like as follow, my

Re: [R] character comp

2019-02-09 Thread Erin Hodgess
Ok. Try something like nchar(mydataframe[,1])-nchar(mydataframe[,2]) On Sat, Feb 9, 2019 at 11:21 AM Erin Hodgess wrote: > Will it always be A’s or will there be a mix please? > > On Sat, Feb 9, 2019 at 11:06 AM Val wrote: > >> Hi All, >> In a given data frame I want to compare character va

Re: [R] character comp

2019-02-09 Thread Val
Hi Erin, Yes, it is always A's. On Sat, Feb 9, 2019 at 12:22 PM Erin Hodgess wrote: > > Will it always be A’s or will there be a mix please? > > On Sat, Feb 9, 2019 at 11:06 AM Val wrote: >> >> Hi All, >> In a given data frame I want to compare character values of two columns. >> My sample d

Re: [R] character comp

2019-02-09 Thread Erin Hodgess
Will it always be A’s or will there be a mix please? On Sat, Feb 9, 2019 at 11:06 AM Val wrote: > Hi All, > In a given data frame I want to compare character values of two columns. > My sample data looks like as follow, > > mydataframe <- read.table( text='ID var1 var2 > R1 AA AAA > R2

[R] character comp

2019-02-09 Thread Val
Hi All, In a given data frame I want to compare character values of two columns. My sample data looks like as follow, mydataframe <- read.table( text='ID var1 var2 R1 AA AAA R2 AAA AAA R3A R4 AA A R5 A AAA', header = TRUE, as.is = TRUE ) For each ID, I want cre