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
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
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
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%
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
> 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
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
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:
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-
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
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
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',
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:
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
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)
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
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
..
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
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
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
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-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
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
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
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
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;
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 =
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
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
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
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
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:
>>
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
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
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
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
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):
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
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
> 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)
>
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
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)
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
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
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-
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
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
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
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
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
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
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
> 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,
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?
--
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" ,
> "
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
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.
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
RRATO2","ODD","SECTION"),
class = "data.frame",row.names = c("1","2", "3", "4", "5",
"6","7","8","9","10","11","12","13"))
expected <-
))
>> 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
;]
> 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
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
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:
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
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
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
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
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"
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
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
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
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
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
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
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
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
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.
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
? 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
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
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
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
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.
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
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
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
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
>
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
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
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
-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
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")])
##
-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
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
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
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
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
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
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
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 - 100 of 293 matches
Mail list logo