Re: [R] matching type question, please

2021-12-17 Thread Rui Barradas
Hello, Inline. Às 23:29 de 16/12/21, Bert Gunter escreveu: Not sure what you mean by this: "But this only works if the vectors xr* are longer than xs*." The solution I gave doesn't care about this. a <- rbind(unique(z2),unique(z1)) a[duplicated(a),] xs1 xs2 ## as before Presumably you

Re: [R] matching type question, please

2021-12-16 Thread Bert Gunter
Not sure what you mean by this: "But this only works if the vectors xr* are longer than xs*." The solution I gave doesn't care about this. > a <- rbind(unique(z2),unique(z1)) > a[duplicated(a),] xs1 xs2 ## as before Presumably you are referring to your use of match() (which is how %in% is de

Re: [R] matching type question, please

2021-12-16 Thread Erin Hodgess
Wow! These are awesome! Thanks so much for the special cases! Erin On Thu, Dec 16, 2021 at 3:52 PM Rui Barradas wrote: > Hello, > > And here is another solution, addressing the problem raised by Bert and > avoiding unique. > > > xr1 <- 8:0 > xr2 <- 0:8 > xs1 <- 9:3 > xs2 <- 4 > cbind(xr1, xr2

Re: [R] matching type question, please

2021-12-16 Thread Rui Barradas
Hello, And here is another solution, addressing the problem raised by Bert and avoiding unique. xr1 <- 8:0 xr2 <- 0:8 xs1 <- 9:3 xs2 <- 4 cbind(xr1, xr2)[(xr1 %in% xs1) & (xr2 %in% xs2),] #xr1 xr2 # 4 4 xr1 <- c(1,2,1) xr2 <- c(4,5,4) xs1 <- c(6,6) xs2 <- c(7,7) cbind(xr1, xr2)[(xr1 %in%

Re: [R] matching type question, please

2021-12-16 Thread Bert Gunter
I am not sure Eric's solution is what is wanted: Consider: xr1 <- c(1,2,1) xr2 <- c(4,5,4) xs1 <- c(6,6) xs2 <- c(7,7) > z1 <- cbind(xr1, xr2) > z2 <- cbind(xs1,xs2) > z1 xr1 xr2 [1,] 1 4 [2,] 2 5 [3,] 1 4 > z2 xs1 xs2 [1,] 6 7 [2,] 6 7 If what is wanted is to find

Re: [R] matching type question, please

2021-12-16 Thread Eric Berger
> a <- cbind(c(xr1,xs1),c(xr2,xs2)) > a[duplicated(a)] [1] 4 4 On Thu, Dec 16, 2021 at 10:18 PM Erin Hodgess wrote: > > Hello! > > I have the following: > > cbind(xr1,xr2) > > xr1 xr2 > > [1,] 8 0 > > [2,] 7 1 > > [3,] 6 2 > > [4,] 5 3 > > [5,] 4 4 > > [6,] 3

[R] matching type question, please

2021-12-16 Thread Erin Hodgess
Hello! I have the following: cbind(xr1,xr2) xr1 xr2 [1,] 8 0 [2,] 7 1 [3,] 6 2 [4,] 5 3 [5,] 4 4 [6,] 3 5 [7,] 2 6 [8,] 1 7 [9,] 0 8 > cbind(xs1,xs2) xs1 xs2 [1,] 9 4 [2,] 8 4 [3,] 7 4 [4,] 6 4 [5,] 5 4

Re: [R] Matching backslash in a table's column using R language

2020-08-25 Thread Peter Bishop
gt;> >> to: >> >> >> "[\x22\x27\x2c\x3f\x5c\x5c\x60]" >> >> >> This seems to be escaping the backslash in the R script rather than in >> the data - which confuses me. >> >> >> From:

Re: [R] Matching backslash in a table's column using R language

2020-08-25 Thread Jeff Newmiller
x22\x27\x2c\x3f\x5c\x5c\x60]" > > >This seems to be escaping the backslash in the R script rather than in >the data - which confuses me. > > >From: Bert Gunter >Sent: Wednesday, 26 August 2020 4:26 AM >To: Peter Bishop >Cc: r-help@r-

Re: [R] Matching backslash in a table's column using R language

2020-08-25 Thread Peter Bishop
5c\x60]" This seems to be escaping the backslash in the R script rather than in the data - which confuses me. From: Bert Gunter Sent: Wednesday, 26 August 2020 4:26 AM To: Peter Bishop Cc: r-help@r-project.org Subject: Re: [R] Matching backslash in a ta

Re: [R] Matching backslash in a table's column using R language

2020-08-25 Thread Bert Gunter
1. I am far from an expert on such matters 2. It is unclear to me what your input is -- I assume a file. The problem, as you indicate, is that R's parser sees "\B" as an incorrect escape character, so, for example: > cat("\B") Error: '\B' is an unrecognized escape in character string starting ""\B

[R] Matching backslash in a table's column using R language

2020-08-25 Thread Peter Bishop
In SQL, I'm using R as a way to filter data based on: - 20 characters in the range to - excluding , , , , , Given a SQL column containing the data: code A\BCDEFG and the T-SQL script: EXEC [sys].[sp_execute_external_script] @language=N'R',

Re: [R] matching doesn't work

2020-04-11 Thread Rasmus Liland
On 2020-04-10 19:05 -0500, Ana Marija wrote: > I am not sure what I am suppose to run > from your codes. Can you just send me > lines of codes which I should run? > (without part where you are loading > your data frames) (assuming my files > are as I showed them) Dear Ana, try these lines:

Re: [R] matching doesn't work

2020-04-10 Thread Ana Marija
I am not sure what I am suppose to run from your codes. Can you just send me lines of codes which I should run? (without part where you are loading your data frames) (assuming my files are as I showed them) Or the whole idea was to remove sep=" " from everywhere? On Fri, Apr 10, 2020 at 7:01 PM R

Re: [R] matching doesn't work

2020-04-10 Thread Rasmus Liland
On 2020-04-10 18:46 -0500, Ana Marija wrote: > so if I understand correctly you would just remove sep=" " from my codes? > > Thank you so much for working on this. > Is there is any chance you can change my original code (pasted bellow) > with changes you think should work? > > library(SNPRelate)

Re: [R] matching doesn't work

2020-04-10 Thread Ana Marija
so if I understand correctly you would just remove sep=" " from my codes? Thank you so much for working on this. Is there is any chance you can change my original code (pasted bellow) with changes you think should work? library(SNPRelate) # get PLINK output plink.genome <- read.table("plink.geno

Re: [R] matching doesn't work

2020-04-10 Thread Rasmus Liland
On 2020-04-10 17:05 -0500, Ana Marija wrote: > it didn't work unfortunately with your > example: > > > plink.genome[idx,] > character(0) Hi! Perhaps csv formatting are better suited for these emails ... the two ibdlist lines I added still matches in this example, added lookup for kinship ..

Re: [R] matching doesn't work

2020-04-10 Thread Ana Marija
it didn't work unfortunately with your example: > plink.genome[idx,] character(0) here is my whole: plink.genome <- read.table("plink.genome", header=TRUE) FID1 IID1 FID2 IID2 RTEZ Z0 Z1 Z2 PI_HAT PHE DST PPC RATIOIBS0IBS1IBS2 HOMHOM HETHET

Re: [R] matching doesn't work

2020-04-10 Thread Rasmus Liland
On 2020-04-10 15:38 -0500, Ana Marija wrote: | Hi, | | I have this code: Dear Ana, none of the ID tuples in the head outputs you provided matches, so I added two lines in ibdlist that matches up; perhaps if you provided more lines that would have matched in a pastebin somewhere ... optio

[R] matching doesn't work

2020-04-10 Thread Ana Marija
Hi, I have this code: library(SNPRelate) # get PLINK output plink.genome <- read.table("plink.genome", header=TRUE) > head(plink.genome) FID1 IID1FID2 IID2 RT EZ Z0 Z1 Z2 PI_HAT PHE DST 1 fam1054 G1054 fam1054 G700 OT 0 0.0045 0.9938 0.0017 0.4986 -1 0.839150 2 fa

Re: [R] Matching Values issue

2019-10-25 Thread Rui Barradas
Hello, That's a floating-point issue. See FAQ 7.31. See also [1], [2] and the links therein. [1] https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal [2] https://stackoverflow.com/questions/588004/is-floating-point-math-broken Hope this helps, Rui Barradas Às 10:00 d

[R] Matching Values issue

2019-10-25 Thread Roberto Martinez Caballero
__ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible cod

Re: [R] Matching multiple search criteria (Unlisting a nested dataset, take 2)

2018-10-19 Thread Ista Zahn
Here is another approach, just for fun: library(tidyverse) library(tokenizers) anyall <- function(x, # a character vector terms # a list of character vectors ){ any(map_lgl(terms, function(term) { all(term %in% x) })) } mutate(th, flag

Re: [R] Matching multiple search criteria (Unlisting a nested dataset, take 2)

2018-10-18 Thread Bert Gunter
Sorry. Typo. The last line should be: ans$Result <- apply(ans,1,function(r)phrasewords[[r[1]]] %allin% tweets[[r[2]]]) -- Bert On Thu, Oct 18, 2018 at 7:04 PM Bert Gunter wrote: > All (especially Nathan): **Please feel free to ignore this post without > response.** It just represents a bit

Re: [R] Matching multiple search criteria (Unlisting a nested dataset, take 2)

2018-10-18 Thread Bert Gunter
All (especially Nathan): **Please feel free to ignore this post without response.** It just represents a bit of OCD-ness on my part that may or may not be of interest to anyone else. Purpose of this post: To give an alternative considerably simpler and considerably faster solution to the problem t

Re: [R] Matching multiple search criteria (Unlisting a nested dataset, take 2)

2018-10-17 Thread Bert Gunter
If you wish to use R, you need to at least understand its basic data structures and functionality. Expecting that mimickry of code in special packages will suffice is, I believe, an illusion. If you haven't already done so, you should go through a basic R tutorial or two (there are many on the web;

Re: [R] Matching multiple search criteria (Unlisting a nested dataset, take 2)

2018-10-17 Thread Nathan Parsons
I do not have your command of base r, Bert. That is a herculean effort! Here’s what I spent my night putting together: ## Create search terms ## dput(st) st <- structure(list(word1 = c("technique", "me", "me", "feel", "feel" ), word2 = c("olympic", "abused", "hurt", "hopeless", "alone" ), word3 =

Re: [R] Matching multiple search criteria (Unlisting a nested dataset, take 2)

2018-10-16 Thread Bert Gunter
OK, as no one else has offered a solution, I'll take a whack at it. Caveats: This is a brute force attempt using R's basic regular expression engine. It is inelegant and barely tested, so likely to be at best incomplete and buggy, and at worst, incorrect. But maybe Nathan or someone else on the li

Re: [R] Matching multiple search criteria (Unlisting a nested dataset, take 2)

2018-10-16 Thread Bert Gunter
The problem wasn't the data tibbles. You posted in html -- which you were explictly warned against -- and that corrupted your text (e.g. some quotes became "smart quotes", which cannot be properly cut and pasted into R). Bert On Tue, Oct 16, 2018 at 2:47 PM Nathan Parsons wrote: > Argh! Here a

Re: [R] Matching multiple search criteria (Unlisting a nested dataset, take 2)

2018-10-16 Thread Nathan Parsons
Argh! Here are those two example datasets as data frames (not tibbles). Sorry again. This apparently is just not my day. th <- structure(list(status_id = c("x1047841705729306624", "x1046966595610927105", "x1047094786610552832", "x1046988542818308097", "x1046934493553221632", "x10472274428997754

[R] Matching multiple search criteria (Unlisting a nested dataset, take 2)

2018-10-16 Thread Nathan Parsons
Thanks all for your patience. Here’s a second go that is perhaps more explicative of what it is I am trying to accomplish (and hopefully in plain text form)... I’m using the following packages: tidyverse, purrr, tidytext I have a number of tweets in the following form: th <- structure(list(st

Re: [R] matching element of a vector to i-2nd element

2017-07-23 Thread Davide Piffer
Thanks a lot, Herve'. This worked! On 23 July 2017 at 22:19, Hervé Pagès wrote: > Hi, > > On 07/23/2017 11:43 AM, Davide Piffer wrote: >> >> I have a df with a vector v. For each element of the vector, I want to >> know whether the i-2nd element is the same as the ith element. For >> example: >>

Re: [R] matching element of a vector to i-2nd element

2017-07-23 Thread Jeff Newmiller
You can compare the elements that make sense to compare, and fill in the ones that don't make sense to compare yourself using the c function. Hint: no looping or if function are necessary. v[ seq( 2, length( v ) ] == v[ seq.int( length( v ) - 2 ) ] -- Sent from my phone. Please excuse my bre

Re: [R] matching element of a vector to i-2nd element

2017-07-23 Thread Hervé Pagès
Hi, On 07/23/2017 11:43 AM, Davide Piffer wrote: I have a df with a vector v. For each element of the vector, I want to know whether the i-2nd element is the same as the ith element. For example: given v=c(A,C,D,C) the result should be: FALSE,FALSE,FALSE,TRUE. I attempted something using indexi

Re: [R] matching element of a vector to i-2nd element

2017-07-23 Thread Davide Piffer
No homework. Just a genuine question On 23 July 2017 at 22:00, Bert Gunter wrote: > Homework?? There is a no homework policy on this list. > > Cheers, > Bert > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Ber

Re: [R] matching element of a vector to i-2nd element

2017-07-23 Thread Bert Gunter
Homework?? There is a no homework policy on this list. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Sun, Jul 23, 2017 at 11:43 AM, Davide Piffer

[R] matching element of a vector to i-2nd element

2017-07-23 Thread Davide Piffer
I have a df with a vector v. For each element of the vector, I want to know whether the i-2nd element is the same as the ith element. For example: given v=c(A,C,D,C) the result should be: FALSE,FALSE,FALSE,TRUE. I attempted something using indexing in a for loop such as (bad, incorrect example):

Re: [R] Matching values between 2 data.frame.

2017-05-20 Thread William Dunlap via R-help
merge() may be useful here: > merge(OriginalData[1:3], TargetValue, by.x="AA1", by.y="AA", sort=FALSE)[-1] Value1 Value2 BB Value 1 1 11 B 7 2 3 13 B 7 3 11 21 B 7 4 2 12 B25 5 12 22 B25 6 9 19 B25 7 10

Re: [R] Matching values between 2 data.frame.

2017-05-20 Thread Bert Gunter
Like this? (use indexing to avoid explicit loops whenever possible): ## first convert factor columns to character, as David W. suggested i <- sapply(od,is.factor) od[i]<- lapply(od[i],as.character) i <- sapply(tv, is.factor) tv[i]<- lapply(tv[i],as.character) ## Now use ?match wh <- match(od

Re: [R] Matching values between 2 data.frame.

2017-05-20 Thread David Winsemius
> On May 20, 2017, at 11:23 AM, Christofer Bogaso > wrote: > > Hi again, > > Let say I have below 2 data frames. > > OriginalData = data.frame('Value1' = 1:12, 'Value2' = 11:22, 'AA1' = > c('AA4', 'AA3', 'AA4', 'AA1', 'AA2', 'AA1', 'AA6', 'AA6', 'AA3', > 'AA3', 'AA4', 'AA3'), 'Value' = NA) >

[R] Matching values between 2 data.frame.

2017-05-20 Thread Christofer Bogaso
Hi again, Let say I have below 2 data frames. OriginalData = data.frame('Value1' = 1:12, 'Value2' = 11:22, 'AA1' = c('AA4', 'AA3', 'AA4', 'AA1', 'AA2', 'AA1', 'AA6', 'AA6', 'AA3', 'AA3', 'AA4', 'AA3'), 'Value' = NA) TargetValue = data.frame('AA' = c('AA1', 'AA2', 'AA3', 'AA4', 'AA5', 'AA6'), 'BB

Re: [R] Matching/checking for occurence when values are double?

2016-09-10 Thread ruipbarradas
Actually, there was another reason for the function equal() but I wasn't remembering what. all.equal doesn't recycle its arguments, just see this example. equal <- function(x, y, eps = .Machine$double.eps^0.5) abs(x - y) < eps x <- seq(0, 1, by = 0.2) x == 0.6 all.equal(x, 0.6) equal(x, 0.6)

Re: [R] Matching/checking for occurence when values are double?

2016-09-09 Thread ruipbarradas
Not exactly, all.equal is much more complete. It accepts all kinds of objects, not just vectors. Rui Barradas Citando Ivan Calandra : Hi, Not sure, but it seems that your function equal() is exactly what all.equal() does, isn't it? Ivan -- Ivan Calandra, PhD Scientific Mediator Univers

Re: [R] Matching/checking for occurence when values are double?

2016-09-09 Thread Jorge Cimentada
Matching 100 to 100.0 or 100.00 or whatever N number of decimales will always return a TRUE. The expression your using is correct. A more complete expression would be kidmomiq[100 == kidmomiq$mom_iq, ]. On Fri, Sep 9, 2016 at 2:01 PM, Matti Viljamaa wrote: I need to pick from a dataset those

Re: [R] Matching/checking for occurence when values are double?

2016-09-09 Thread Ivan Calandra
Hi, Not sure, but it seems that your function equal() is exactly what all.equal() does, isn't it? Ivan -- Ivan Calandra, PhD Scientific Mediator University of Reims Champagne-Ardenne GEGENAA - EA 3795 CREA - 2 esplanade Roland Garros 51100 Reims, France +33(0)3 26 77 36 89 ivan.calan...@univ-

Re: [R] Matching/checking for occurence when values are double?

2016-09-09 Thread ruipbarradas
Hello, See FAQ 7.31. It's irrelevant if you write 100 or 100.0, the values are the same. The difference would be between 100 (double) and 100L (integer). To check for equality between floating-point numbers you can use, for instance, the following function. equal <- function(x, y, eps = .Ma

[R] Matching/checking for occurence when values are double?

2016-09-09 Thread Matti Viljamaa
I need to pick from a dataset those rows that have a double value set to 100. However since the values in this column are like the following: [1] 121.11750 89.36188 115.44320 99.44964 92.74571 107.90180 [7] 138.89310 125.14510 81.61953 95.07307 88.57700 94.85971 [13] 88.96280 114.11430 100

[R] Matching posterior probabilities from poLCA

2015-08-03 Thread Rob de Vries
Hi all, I'm a newbie to R with a question about poLCA. When you run a latent class analysis in poLCA it generates a value for each respondent giving their posterior probability of 'belonging' to each latent class. These are stored as a matrix in the element 'posterior'. I would like to create a d

Re: [R] matching strings in a list

2015-07-17 Thread tryingtolearn
Thank you all very much! -- View this message in context: http://r.789695.n4.nabble.com/matching-strings-in-a-list-tp4709967p4710015.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE

Re: [R] matching strings in a list

2015-07-16 Thread John McKown
On Thu, Jul 16, 2015 at 1:00 PM, John McKown wrote: > On Thu, Jul 16, 2015 at 12:40 PM, tryingtolearn > wrote: > >> Say I have a list: >> [[1]] "I like google" >> [[2]] "Hi Google google" >> [[3]] "what's up" >> >> and they are tweets. And I want to find out how many tweets mention google >> (th

Re: [R] matching strings in a list

2015-07-16 Thread John McKown
On Thu, Jul 16, 2015 at 12:40 PM, tryingtolearn wrote: > Say I have a list: > [[1]] "I like google" > [[2]] "Hi Google google" > [[3]] "what's up" > > and they are tweets. And I want to find out how many tweets mention google > (the answer should be 2). > If I string split and unlist them, then I

Re: [R] matching strings in a list

2015-07-16 Thread Ista Zahn
Why would you strsplit them? I would think length(grep("google", unlist(x), ignore.case = TRUE)) should do it. Best, Ista On Thu, Jul 16, 2015 at 1:40 PM, tryingtolearn wrote: > Say I have a list: > [[1]] "I like google" > [[2]] "Hi Google google" > [[3]] "what's up" > > and they are tweets. A

Re: [R] matching strings in a list

2015-07-16 Thread Marc Schwartz
> On Jul 16, 2015, at 12:40 PM, tryingtolearn wrote: > > Say I have a list: > [[1]] "I like google" > [[2]] "Hi Google google" > [[3]] "what's up" > > and they are tweets. And I want to find out how many tweets mention google > (the answer should be 2). > If I string split and unlist them,

[R] matching strings in a list

2015-07-16 Thread tryingtolearn
Say I have a list: [[1]] "I like google" [[2]] "Hi Google google" [[3]] "what's up" and they are tweets. And I want to find out how many tweets mention google (the answer should be 2). If I string split and unlist them, then I would get the answer of 3. How do I make sure I get just 2? --

Re: [R] matching genes to a list of gene groups an built binary data frame

2014-10-20 Thread David Winsemius
On Oct 20, 2014, at 6:28 AM, Karim Mezhoud wrote: > Genes <- c("ACACA", "BAX" , "BCL2", "BID", "BAX", "MAPK9") > > and a list of group of genes > > ListGroup <- list(group1=c("ACACA" ,"AHSA1" ,"AIMP2", "AKR1B1", > "AKT1", "AKT1S1"), group2=c("ANXA1" , "AR" , "ARID1A" , > "

[R] matching genes to a list of gene groups an built binary data frame

2014-10-20 Thread Karim Mezhoud
Dear All, I have a gene list Genes <- c("ACACA", "BAX" , "BCL2", "BID", "BAX", "MAPK9") and a list of group of genes ListGroup <- list(group1=c("ACACA" ,"AHSA1" ,"AIMP2", "AKR1B1", "AKT1", "AKT1S1"), group2=c("ANXA1" , "AR" , "ARID1A" , "ATM" , "BAK1" , "BAX" ), g

Re: [R] Matching data in two files but returning a value from a adjacent column

2014-01-23 Thread arun
Hi, Try ?merge() or ?join() from library(plyr) #Please provide reproducible example.  set.seed(42)  dat1 <- data.frame(Stat_Ana=sample(20:30,10,replace=TRUE)) dat2 <- data.frame(Stat_Ana=20:30,Group=LETTERS[1:11]) merge(dat1,dat2,by="Stat_Ana") library(plyr)  join(dat1,dat2,by="Stat_Ana") A.K.

[R] matching columns of model matrix to those in original data.frame

2013-07-26 Thread Ross Boylan
What is a reliable way to go from a column of a model matrix back to the column (or columns) of the original data source used to make the model matrix? I can come up with a method that seems to work, but I don't see guarantees in the documentation that it will. In particular, does the order of

Re: [R] matching similar character strings

2013-07-09 Thread A M Lavezzi
RRATO2","ODD","SECTION"), class = "data.frame",row.names = c("1","2", "3", "4", "5", "6","7","8","9","10","11","12","13")) expected <-

Re: [R] matching similar character strings

2013-07-06 Thread Jeff Newmiller
)) >> F1_ex[,1]<-F2_ex[sapply(vec2,function(x) which((x>F2_ex[,4] & x< >F2_ex[,6]) & paste(F2_ex[,2],F2_ex[,3])%in%vec1)),"SECTION"] >> F1_ex >> # Nome.azienda Indirizzo >> #17 1261 Via Edmondo De Amicis, 18 >> #18

Re: [R] matching similar character strings

2013-07-06 Thread A M Lavezzi
;] > F1_ex > # Nome.azienda Indirizzo > #17 1261 Via Edmondo De Amicis, 18 > #18 1262 Via Edmondo De Amicis, 65 > A.K. > > > > > > - Original Message - > From: A M Lavezzi > To: r-help > Cc: > Sent: Tuesday, Jul

Re: [R] matching similar character strings

2013-07-03 Thread arun
some matching pairs within the example > dataset.  Also, please post it to r-help as I will be able to check only > after a couple of hours > Tx. > Arun > > > > - Original Message - > From: Mario Lavezzi > To: arun > Cc: > Sent: Friday, June 21, 201

Re: [R] matching similar character strings

2013-07-02 Thread A M Lavezzi
the > name is slightly different, element A15 should be added to row 1) of F1, > producing an output such as: > > 1) Street | J.F. Kennedy | 30 | A15 > > > hope this clarifies the issue. > > thanks a lot! Mario > > > > Il 21/06/2013 15:29, arun ha scritto:

Re: [R] matching similar character strings

2013-06-21 Thread David Carlson
t" "e Ave" "e Rd" "e St" "f Ave" "f Rd" "f St" [19] "g Ave" "g Rd" "g St" "h Ave" "h Rd" "h St" "i Ave" "i Rd" "i St" [28] "j Ave&qu

[R] matching similar character strings

2013-06-21 Thread A M Lavezzi
Hello everybody I have this problem: I need to match an addresses database F1 with the information contained in a toponymic database F2. The format of F1 is given by three columns and 800 rows, with the columns being: A1. Street/Road/Avenue A2. Name A3. Number Consider for instance Avenue J. Ke

Re: [R] Matching names with non-English characters

2013-05-13 Thread Duncan Murdoch
On 13/05/2013 12:05 PM, Spencer Graves wrote: Hello: How can one match names containing non-English characters that appear differently in different but related data files? For example, I have data on Raúl Grijalva, who represents the third district of Arizona in the US House of Represe

Re: [R] Matching names with non-English characters

2013-05-13 Thread Jeff Newmiller
Build a lookup table for your data. I think it is a fools errand to think that you can automatically "normalize" arbitrary Unicode characters to an ASCII form that everyone will agree on. BTW: To avoid propagating open joins your data should probably have some kind of id for the term those Repr

[R] Matching names with non-English characters

2013-05-13 Thread Spencer Graves
Hello: How can one match names containing non-English characters that appear differently in different but related data files? For example, I have data on Raúl Grijalva, who represents the third district of Arizona in the US House of Representatives. This first name appears as "Raúl"

Re: [R] matching observations and ranking

2013-04-24 Thread arun
Just to add: If your original dataset have only few columns, then you can try this too: res1<-within(mutate(dat1,AB001A_1=1*(AB001A==AB001A[2]),AB0002A_1=1*(AB0002A==AB0002A[2]),AB362_1=1*(AB362==AB362[2]),SUM=rowSums(cbind(AB001A_1,AB0002A_1,AB362_1)),MATCH=(SUM/3)*100),{MATCH[1:2]<-NA;RANK=rank(M

Re: [R] matching observations and ranking

2013-04-24 Thread arun
Hi, May be this helps: As you wanted to match only from row3 onwards to row2, the corresponding values on row1 and row2 were set to NA. dat1<- read.table(text="   S.No AB001A AB0002A AB362    P1   -/-    C/C   A/A       P2   C/C    C/C   A/A      

Re: [R] matching observations and ranking

2013-04-23 Thread arun
Hi, It is not that clear. If VAR1 is a match between columns AB001A, AB0002A, VAR2  between AB001A, AB362 and VAR3 between AB0002A and AB362: Also, I assume row8 match would be taken as 1. dat1<- read.table(text="   S.No AB001A AB0002A AB362    1   -/-    C/C   A/A      

Re: [R] matching multiple fields from a matrix

2013-04-16 Thread jercrowley
011 #222 18901415 #325 18801114 #430 18601050 A.K. - Original Message - From: jercrowley <[hidden email]> To: [hidden email] Cc: Sent: Monday, April 15, 2013 5:07 PM Subject: [R] matching multiple fields from a matrix I have been trying many w

Re: [R] matching multiple fields from a matrix

2013-04-15 Thread arun
0    14    15 #3    25 1880    11    14 #4    30 1860    10    50 A.K. - Original Message - From: jercrowley To: r-help@r-project.org Cc: Sent: Monday, April 15, 2013 5:07 PM Subject: [R] matching multiple fields from a matrix I have been trying many ways to match 2 separate fields in

[R] matching multiple fields from a matrix

2013-04-15 Thread jercrowley
I have been trying many ways to match 2 separate fields in a matrix. Here is a simplified version of the matrix: site1 depth1 year1 site2 depth2 year2 10 30 1860NA NA NA NA NA NA 50 30 1860 Basically I am trying to identify the sites which

Re: [R] matching a string with multiple conditions using grep

2012-06-23 Thread arun
Original Message - From: Zhipeng Wang To: r-help@r-project.org Cc: Sent: Saturday, June 23, 2012 6:19 AM Subject: [R] matching a string with multiple conditions using grep Suppose I have a vector  ["A_cont_1", "A_cont_12", "B_treat_8", "AB_cont_22&qu

Re: [R] matching a string with multiple conditions using grep

2012-06-23 Thread Zhipeng Wang
ot;, "AB_cont_22", "cont_21_Aa") > vec2<-grep("(A){0,1}.*cont.*2",vec1) > > vec1[vec2] > [1] "A_cont_12" "AB_cont_22" "cont_21_Aa" > > > A.K. > > > > > ----- Original Message - > From: Zhipeng

Re: [R] matching a string with multiple conditions using grep

2012-06-23 Thread Rui Barradas
Hello, Try the following. wanted <- c("A_cont_12", "AB_cont_22", "cont_21_Aa") x <- c("A_cont_1", "A_cont_12", "B_treat_8", "AB_cont_22", "cont_21_Aa") pattern <- c("A", "cont", "2") ix <- Reduce(`&`, lapply(pattern, grepl, x)) # This does the trick identical(wanted, x[ix]) See ?Reduce.

[R] matching a string with multiple conditions using grep

2012-06-23 Thread Zhipeng Wang
Suppose I have a vector ["A_cont_1", "A_cont_12", "B_treat_8", "AB_cont_22", "cont_21_Aa"], I hope I can extract the strings which include 3 short strings, say "A", "cont" and "2", that is to say, "A_cont_12", "AB_cont_22" and "cont_21_Aa" will be extract, using a relatively short code (using gr

Re: [R] Matching - finding and listing data that is one object but not in another

2012-05-11 Thread R. Michael Weylandt
? setdiff Michael On May 11, 2012, at 8:50 AM, James Holland wrote: > What is the best way to find out what elements/numbers that are in one > object are not in another. > > > I came up with this method, but I'm wondering if there is a more efficient > way (and one that doesn't seem so "clunk

[R] Matching - finding and listing data that is one object but not in another

2012-05-11 Thread James Holland
What is the best way to find out what elements/numbers that are in one object are not in another. I came up with this method, but I'm wondering if there is a more efficient way (and one that doesn't seem so "clunky"). #Example id <- c(1,2,3,4,5,6,7,9,10) example.1 <- data.frame(id) #Second ob

Re: [R] matching a sequence in a vector?

2012-02-16 Thread Berend Hasselman
On 16-02-2012, at 09:01, Petr Savicky wrote: > > Hi. > > There were several solutions in this thread. Their speed differs > quite significantly. Here is a comparison. > > patrn <- 1:4 > exmpl <- sample(1:4, 1, replace=TRUE) > > occur1 <- function(patrn, exmpl) > { >m <- length(pat

Re: [R] matching a sequence in a vector?

2012-02-16 Thread Petr Savicky
On Wed, Feb 15, 2012 at 08:12:32PM -0500, Gabor Grothendieck wrote: > On Tue, Feb 14, 2012 at 11:17 PM, Redding, Matthew > wrote: > > I've been trawling through the documentation and listserv archives on this > > topic -- but > > as yet have not found a solution.  I'm sure this is pretty simple w

Re: [R] matching a sequence in a vector?

2012-02-15 Thread Gabor Grothendieck
On Tue, Feb 14, 2012 at 11:17 PM, Redding, Matthew wrote: > I've been trawling through the documentation and listserv archives on this > topic -- but > as yet have not found a solution.  I'm sure this is pretty simple with R, but > I cannot work out how without > resorting to ugly nested loops.

Re: [R] matching a sequence in a vector?

2012-02-15 Thread jim holtman
egards > > Matt > > > >>-Original Message- >>From: r-help-boun...@r-project.org >>[mailto:r-help-boun...@r-project.org] On Behalf Of Berend Hasselman >>Sent: Thursday, 16 February 2012 1:35 AM >>To: Martin Morgan >>Cc: r-help@r-project.org >>S

Re: [R] matching a sequence in a vector?

2012-02-15 Thread Redding, Matthew
selman >Sent: Thursday, 16 February 2012 1:35 AM >To: Martin Morgan >Cc: r-help@r-project.org >Subject: Re: [R] matching a sequence in a vector? > > >On 15-02-2012, at 15:27, Martin Morgan wrote: > >> On 02/14/2012 11:45 PM, Petr Savicky wrote: >>> On Wed, Feb 1

Re: [R] matching a sequence in a vector?

2012-02-15 Thread Berend Hasselman
On 15-02-2012, at 15:27, Martin Morgan wrote: > On 02/14/2012 11:45 PM, Petr Savicky wrote: >> On Wed, Feb 15, 2012 at 02:17:35PM +1000, Redding, Matthew wrote: >>> Hi All, >>> >>> >>> I've been trawling through the documentation and listserv archives on this >>> topic -- but >>> as yet have n

Re: [R] matching a sequence in a vector?

2012-02-15 Thread Petr Savicky
On Wed, Feb 15, 2012 at 06:27:01AM -0800, Martin Morgan wrote: > On 02/14/2012 11:45 PM, Petr Savicky wrote: > >On Wed, Feb 15, 2012 at 02:17:35PM +1000, Redding, Matthew wrote: > >>Hi All, > >> > >> > >>I've been trawling through the documentation and listserv archives on > >>this topic -- but >

Re: [R] matching a sequence in a vector?

2012-02-15 Thread Martin Morgan
On 02/14/2012 11:45 PM, Petr Savicky wrote: On Wed, Feb 15, 2012 at 02:17:35PM +1000, Redding, Matthew wrote: Hi All, I've been trawling through the documentation and listserv archives on this topic -- but as yet have not found a solution. I'm sure this is pretty simple with R, but I cannot

Re: [R] matching a sequence in a vector?

2012-02-15 Thread Petr Savicky
On Wed, Feb 15, 2012 at 10:26:44AM +0100, Berend Hasselman wrote: > > On 15-02-2012, at 05:17, Redding, Matthew wrote: > > > Hi All, > > > > > > I've been trawling through the documentation and listserv archives on this > > topic -- but > > as yet have not found a solution. I'm sure this is p

Re: [R] matching a sequence in a vector?

2012-02-15 Thread Berend Hasselman
On 15-02-2012, at 05:17, Redding, Matthew wrote: > Hi All, > > > I've been trawling through the documentation and listserv archives on this > topic -- but > as yet have not found a solution. I'm sure this is pretty simple with R, but > I cannot work out how without > resorting to ugly nested

Re: [R] matching a sequence in a vector?

2012-02-15 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 15/02/12 05:17, Redding, Matthew wrote: > Hi All, > > > I've been trawling through the documentation and listserv archives > on this topic -- but as yet have not found a solution. I'm sure > this is pretty simple with R, but I cannot work out how

Re: [R] matching a sequence in a vector?

2012-02-15 Thread chuck.01
this is ugly, but... l <-length(patrn) l2 <-length(exmpl) out <- vector("list") for(i in 1:(l2-l+1)) { exmpl[i:(i+l-1)] patrn==exmpl[i:(i+l-1)] if(all(patrn==exmpl[i:(i+l-1)])) { out[[i]] <- i } else { out[[i]] <- "NA"} } out <- do.call(c, out) as.numeric(out[which(out!="NA")]) ##

Re: [R] matching a sequence in a vector?

2012-02-15 Thread Rainer M Krug
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 15/02/12 05:17, Redding, Matthew wrote: > Hi All, > > > I've been trawling through the documentation and listserv archives > on this topic -- but as yet have not found a solution. I'm sure > this is pretty simple with R, but I cannot work out how

Re: [R] matching a sequence in a vector?

2012-02-15 Thread Petr Savicky
On Wed, Feb 15, 2012 at 02:17:35PM +1000, Redding, Matthew wrote: > Hi All, > > > I've been trawling through the documentation and listserv archives on this > topic -- but > as yet have not found a solution. I'm sure this is pretty simple with R, but > I cannot work out how without > resorting

Re: [R] matching a sequence in a vector?

2012-02-14 Thread Petr Savicky
On Wed, Feb 15, 2012 at 02:17:35PM +1000, Redding, Matthew wrote: > Hi All, > > > I've been trawling through the documentation and listserv archives on this > topic -- but > as yet have not found a solution. I'm sure this is pretty simple with R, but > I cannot work out how without > resorting

[R] matching a sequence in a vector?

2012-02-14 Thread Redding, Matthew
Hi All, I've been trawling through the documentation and listserv archives on this topic -- but as yet have not found a solution. I'm sure this is pretty simple with R, but I cannot work out how without resorting to ugly nested loops. As far as I can tell, grep, match, and %in% are not the co

Re: [R] matching using "which"

2011-12-08 Thread R. Michael Weylandt
Here's one that is perhaps a little simpler: simply drop the which and use logical indexing. dat <- matrix(1:6, 2); colnames(dat) <- c("A","B","A") dat[, colnames(dat) %in% "A"] dat[, colnames(dat) %in% "B"] # Note that you may want drop = FALSE dat[, colnames(dat) %in% "C"] dat[, !(colnames(dat

Re: [R] matching using "which"

2011-12-08 Thread andrija djurovic
Hi. Here is one approach: if (length(b)>0) data[,-b] else data Andrija On Thu, Dec 8, 2011 at 1:25 PM, Vikram Bahure wrote: > Dear R users, > > I have a very simple query. > > I am using the following command, which should give me row no. for the > matching colnames. It works well for matching

[R] matching using "which"

2011-12-08 Thread Vikram Bahure
Dear R users, I have a very simple query. I am using the following command, which should give me row no. for the matching colnames. It works well for matching the colnames but if there is no column matching it gives me outcome as integer(0) which I am not able to use in further calculation. It wo

Re: [R] Matching

2011-10-29 Thread Joshua Wiley
Hi Shishm, Part of what you do seems reasonable. My guess is that: o <- match(OID_, OID_) is not doing what you want/think. What happens when you look at the results? e.g.,: print(o) You use that later on as row and column indices to extract from m, to create m1. The fact taht mat2listw co

  1   2   3   >