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

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

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,

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

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
;> >> >> "[\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

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

2020-08-25 Thread Jeff Newmiller
c\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-pr

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

2020-08-25 Thread Peter Bishop
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-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

[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

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? > >

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 <-

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

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 ...

[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

Re: [R] Matching Values issue

2019-10-26 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

[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

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,

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

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

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

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

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",

[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 <-

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

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

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

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

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

[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

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 <-

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',

[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'),

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,

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

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

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 =

[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

[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

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

[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? -- View

Re: [R] matching strings in a list

2015-07-16 Thread Marc Schwartz
On Jul 16, 2015, at 12:40 PM, tryingtolearn inshi...@ymail.com 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

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 inshi...@ymail.com wrote: Say I have a list: [[1]] I like google [[2]] Hi Google google [[3]] what's up and they are

Re: [R] matching strings in a list

2015-07-16 Thread John McKown
On Thu, Jul 16, 2015 at 12:40 PM, tryingtolearn inshi...@ymail.com 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,

Re: [R] matching strings in a list

2015-07-16 Thread John McKown
On Thu, Jul 16, 2015 at 1:00 PM, John McKown john.archie.mck...@gmail.com wrote: On Thu, Jul 16, 2015 at 12:40 PM, tryingtolearn inshi...@ymail.com 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

[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 ), group3=c(BCL2 ,BCL2L1 , BCL2L11

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 , ATM , BAK1 , BAX ),

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. I

[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

Re: [R] matching similar character strings

2013-07-09 Thread A M Lavezzi
, 2013 8:36 AM Subject: Re: [R] matching similar character strings Dear Arun, thank you so much! The code you suggest captures what we have in mind. However, what we are looking for is something a bit more general (sorry: I realised that maybe this was not so clear from the beginning

Re: [R] matching similar character strings

2013-07-06 Thread A M Lavezzi
:22 AM Subject: Re: [R] matching similar character strings Dear Arun, please excuse me for this late reply, we had to stop working on this temporaririly. Let me reproduce here two examples of rows from F1 and F2 (sorry, but with dput() I am not able to produce a clear example) F1_ex

Re: [R] matching similar character strings

2013-07-06 Thread Jeff Newmiller
Subject: Re: [R] matching similar character strings Dear Arun, please excuse me for this late reply, we had to stop working on this temporaririly. Let me reproduce here two examples of rows from F1 and F2 (sorry, but with dput() I am not able to produce a clear example) F1_ex

Re: [R] matching similar character strings

2013-07-03 Thread arun
: Re: [R] matching similar character strings Dear Arun, please excuse me for this late reply, we had to stop working on this temporaririly. Let me reproduce here two examples of rows from F1 and F2 (sorry, but with dput() I am not able to produce a clear example) F1_ex         Nome.azienda

Re: [R] matching similar character strings

2013-07-02 Thread A M Lavezzi
:08 AM Subject: Re: [R] matching similar character strings dear Arun thank you very much. Let me explain the problem: Imagine that a portion of the row in F1 is: F1 1) Street | J.F. Kennedy | 30 it means that our unit

[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.

Re: [R] matching similar character strings

2013-06-21 Thread David Carlson
L Carlson Associate Professor of Anthropology Texas AM University College Station, TX 77840-4352 -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of A M Lavezzi Sent: Friday, June 21, 2013 4:56 AM To: r-help Subject: [R] matching similar

[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 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

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

Re: [R] matching observations and ranking

2013-04-24 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 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       3 

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:

Re: [R] matching multiple fields from a matrix

2013-04-16 Thread jercrowley
. - Original Message - From: jercrowley [hidden email]/user/SendEmail.jtp?type=nodenode=4664328i=0 To: [hidden email]/user/SendEmail.jtp?type=nodenode=4664328i=1 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

[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

Re: [R] matching multiple fields from a matrix

2013-04-15 Thread arun
: jercrowley jcrowl...@mtech.edu 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 a matrix.  Here is a simplified version of the matrix: site1    depth1    year1    site2

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

2012-06-24 Thread arun
, 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, 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

[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 grep?). Would you

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. Hope this helps, Rui

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

2012-06-23 Thread Zhipeng Wang
-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 Wang wa...@kuhp.kyoto-u.ac.jp To: r-help@r-project.org Cc: Sent: Saturday, June 23, 2012 6:19 AM Subject: [R] matching a string with multiple conditions using

[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

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

2012-05-11 Thread R. Michael Weylandt michael.weyla...@gmail.com
? setdiff Michael On May 11, 2012, at 8:50 AM, James Holland holland.ag...@gmail.com 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

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 matthew.redd...@deedi.qld.gov.au wrote: I've been trawling through the documentation and listserv archives on this topic -- but as yet have not found a solution.  I'm

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(patrn) n -

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 to

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)]) ## Cheers and

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 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 loops.

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 pretty simple

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

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 as yet have not

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 not found a solution.

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

2012-02-15 Thread Redding, Matthew
: 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 15, 2012 at 02:17:35PM +1000, Redding, Matthew wrote: Hi All

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

2012-02-15 Thread jim holtman
[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 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

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 matthew.redd...@deedi.qld.gov.au 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

[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

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 to

[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

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 economics.vik...@gmail.comwrote: 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

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) %in% A)] #

[R] Matching

2011-10-29 Thread shish matt
I have a spatial weight file in csv that I want as listw object in R. The file has the following 3 variables (left to right in the file) -- OID_, NID and WEIGHTS. NID stands for the neighbors and OID_ as the origins. There are 217 origins with 4 neighbors each. I have been able to read the csv

  1   2   3   >