[R] match

2007-11-22 Thread Marco chiapello
Hi,
I'm new about R. My problem is:
I have 2 lists of proteins and I would compare them. I import the 2  
lists like 2 different matrixs and I would that the first entry in the  
matrix 1 match with all entries of the matrix 2, then the second entry  
of the matrix 1 matchs with all entries of the matrix 2 and repeat  
this process with all entries of the matrix 1. Anybodies know can I do  
it?
Thanks,
Marco
-
Contatti
  *Mail:
   [EMAIL PROTECTED]
   [EMAIL PROTECTED]
  *Messanger:
   [EMAIL PROTECTED]
  *Skype:
   marpello
  *Sito:
   http://web.mac.com/marpello/iWeb/Sito/index.html

__
R-help@r-project.org mailing list
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 code.


[R] match

2008-12-02 Thread threshold

Hi, I would like to check which rows of 'types.prev' matrix pop up in
'types', following R in-built procedure. I tried 'match' function but it
works in case of the one dimensional vectors.
Will appreciate any suggestions. 
best, robert 

> types
 edateK  
 [1,] 20060819 12.5 
 [2,] 20060819 17.5 
 [3,] 20060819 22.5 
 [4,] 20070217 12.5 
 [5,] 20060617 10.0 
 [6,] 20060617 15.0 
 [7,] 20060520 12.5 
 [8,] 20060520 15.0 
 [9,] 20060520 17.5 
[10,] 20061118 10.0 
[11,] 20061118 12.5 
[12,] 20061118 15.0 
[13,] 20061118 17.5 

> types.prev
 edateK  
 [1,] 20060819 10.0 
 [2,] 20060819 12.5 
 [3,] 20060819 17.5 
 [4,] 20070217 10.0 
 [5,] 20070217 12.5 
 [6,] 20070217 15.0 
 [7,] 20060617 10.0 
 [8,] 20060617 12.5 
 [9,] 20060617 15.0 
[10,] 20060617 20.0
[11,] 20060520 10.0
[12,] 20060520 12.5
[13,] 20060520 17.5
[14,] 20061118 12.5
[15,] 20061118 15.0
[16,] 20061118 17.5


-- 
View this message in context: 
http://www.nabble.com/match-tp20799206p20799206.html
Sent from the R help mailing list archive at Nabble.com.

__
R-help@r-project.org mailing list
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 code.


Re: [R] match

2007-11-22 Thread jim holtman
Can you provide an example of the input data and what you would like
the output to be.  When you say "first entry" is this a single cell,
or the whole row?  So an example would help to understand what you are
after.

On Nov 22, 2007 8:45 AM, Marco chiapello <[EMAIL PROTECTED]> wrote:
> Hi,
> I'm new about R. My problem is:
> I have 2 lists of proteins and I would compare them. I import the 2
> lists like 2 different matrixs and I would that the first entry in the
> matrix 1 match with all entries of the matrix 2, then the second entry
> of the matrix 1 matchs with all entries of the matrix 2 and repeat
> this process with all entries of the matrix 1. Anybodies know can I do
> it?
> Thanks,
> Marco
> -
> Contatti
>  *Mail:
>   [EMAIL PROTECTED]
>   [EMAIL PROTECTED]
>  *Messanger:
>   [EMAIL PROTECTED]
>  *Skype:
>   marpello
>  *Sito:
>   http://web.mac.com/marpello/iWeb/Sito/index.html
>
> __
> R-help@r-project.org mailing list
> 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 code.
>



-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

__
R-help@r-project.org mailing list
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 code.


Re: [R] match

2008-12-02 Thread Peter Alspach
Tena koe Robert

You could first apply paste

apply(types, 1, paste, collapse=':')

and then match.

HTH 

Peter Alspach 

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of threshold
> Sent: Wednesday, 3 December 2008 8:32 a.m.
> To: r-help@r-project.org
> Subject: [R] match
> 
> 
> Hi, I would like to check which rows of 'types.prev' matrix 
> pop up in 'types', following R in-built procedure. I tried 
> 'match' function but it works in case of the one dimensional vectors.
> Will appreciate any suggestions. 
> best, robert 
> 
> > types
>  edateK  
>  [1,] 20060819 12.5
>  [2,] 20060819 17.5
>  [3,] 20060819 22.5
>  [4,] 20070217 12.5
>  [5,] 20060617 10.0
>  [6,] 20060617 15.0
>  [7,] 20060520 12.5
>  [8,] 20060520 15.0
>  [9,] 20060520 17.5
> [10,] 20061118 10.0
> [11,] 20061118 12.5
> [12,] 20061118 15.0
> [13,] 20061118 17.5 
> 
> > types.prev
>  edateK  
>  [1,] 20060819 10.0
>  [2,] 20060819 12.5
>  [3,] 20060819 17.5
>  [4,] 20070217 10.0
>  [5,] 20070217 12.5
>  [6,] 20070217 15.0
>  [7,] 20060617 10.0
>  [8,] 20060617 12.5
>  [9,] 20060617 15.0
> [10,] 20060617 20.0
> [11,] 20060520 10.0
> [12,] 20060520 12.5
> [13,] 20060520 17.5
> [14,] 20061118 12.5
> [15,] 20061118 15.0
> [16,] 20061118 17.5
> 
> 
> --
> View this message in context: 
> http://www.nabble.com/match-tp20799206p20799206.html
> Sent from the R help mailing list archive at Nabble.com.
> 
> __
> R-help@r-project.org mailing list
> 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 code.
> 

The contents of this e-mail are confidential and may be subject to legal 
privilege.
 If you are not the intended recipient you must not use, disseminate, 
distribute or
 reproduce all or any part of this e-mail or attachments.  If you have received 
this
 e-mail in error, please notify the sender and delete all material pertaining 
to this
 e-mail.  Any opinion or views expressed in this e-mail are those of the 
individual
 sender and may not represent those of The New Zealand Institute for Plant and
 Food Research Limited.

__
R-help@r-project.org mailing list
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 code.


[R] match() indexing

2009-07-01 Thread Hane, Christopher A
 
 Hello,

I'm trying to vectorize some assignment statements using match(), but
can't seem to get it correct.

I have 2 data frames each with a key column of unique values. I want to
copy a column from one frame to another where the key values are the
same.  The data frames are not the same length, and the set of keys is
non-overlapping (each frame has keys not in the other).

Example:
x <- data.frame(id=c(1,3,4,6,7,9,10), r=runif(7))
> x
  id r
1  1 0.4243219
2  3 0.2389127
3  4 0.7094532
4  6 0.2053836
5  7 0.9630027
6  9 0.1218458
7 10 0.9183175
> y <- data.frame(id=c(1,2,4,7,8,9,10,11,12))
> y
  id
1  1
2  2
3  4
4  7
5  8
6  9
7 10
8 11
9 12

I want to copy the x$r values to y to obtain
>y
  idr
1  10.4243219
2  2NA
3  40.7094532
4  70.9630027
5  8NA
6  90.1218458
7 100.9183175
8 11NA
9 12NA

xIdx <- match(x$id,y$id) yields a vector of length x, so it cannot be
used directly to copy to y. 

Any help in vectorizing this assignment would be most welcome.

Chris

This e-mail, including attachments, may include confidential and/or
proprietary information, and may be used only by the person or entity
to which it is addressed. If the reader of this e-mail is not the intended
recipient or his or her authorized agent, the reader is hereby notified
that any dissemination, distribution or copying of this e-mail is
prohibited. If you have received this e-mail in error, please notify the
sender by replying to this message and delete this e-mail immediately.

__
R-help@r-project.org mailing list
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 code.


[R] match and incomparables

2008-09-12 Thread McGehee, Robert
Hello,
I was playing around with the newly implemented 'incomparables' argument
in 'match' and realized the argument does not behave anything like I
expected. Can someone explain what is going on here? Sorry if I'm
misreading the documentation.

> match(1:3, 1:3, incomparables=1)
[1] NA  2  3  # This seems right, the 1 in 'x' is 'incomparable'

> match(1:3, 1:3, incomparables=2)
[1] 1  2  3   # Shouldn't this be 1 NA 3? Why isn't the 2 incomparable?

> match(1:3, 1:3, incomparables=5)
[1] NA  2  3   # Why isn't the 5 ignored?

Note from ?match:
"incomparables: a vector of values that cannot be matched. Any value in
x matching a value in this vector is assigned the nomatch value. For
historical reasons, FALSE is equivalent to NULL."

Thanks in advance!
Robert

platform   i386-pc-mingw32 
arch   i386
os mingw32 
system i386, mingw32   
status 
major  2   
minor  7.2 
year   2008
month  08  
day25  
svn rev46428   
language   R   
version.string R version 2.7.2 (2008-08-25)

Robert McGehee, CFA
Geode Capital Management, LLC
One Post Office Square, 28th Floor | Boston, MA | 02109
Tel: 617/392-8396Fax:617/476-6389
mailto:[EMAIL PROTECTED]



This e-mail, and any attachments hereto, are intended fo...{{dropped:12}}

__
R-help@r-project.org mailing list
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 code.


Re: [R] match() indexing

2009-07-01 Thread Jorge Ivan Velez
Dear Christopher,
Try this:

merge(x,y,all=TRUE)

HTH,

Jorge


On Wed, Jul 1, 2009 at 2:51 PM, Hane, Christopher A <
christopher.h...@ingenixconsulting.com> wrote:

>
>  Hello,
>
> I'm trying to vectorize some assignment statements using match(), but
> can't seem to get it correct.
>
> I have 2 data frames each with a key column of unique values. I want to
> copy a column from one frame to another where the key values are the
> same.  The data frames are not the same length, and the set of keys is
> non-overlapping (each frame has keys not in the other).
>
> Example:
> x <- data.frame(id=c(1,3,4,6,7,9,10), r=runif(7))
> > x
>  id r
> 1  1 0.4243219
> 2  3 0.2389127
> 3  4 0.7094532
> 4  6 0.2053836
> 5  7 0.9630027
> 6  9 0.1218458
> 7 10 0.9183175
> > y <- data.frame(id=c(1,2,4,7,8,9,10,11,12))
> > y
>  id
> 1  1
> 2  2
> 3  4
> 4  7
> 5  8
> 6  9
> 7 10
> 8 11
> 9 12
>
> I want to copy the x$r values to y to obtain
> >y
>  idr
> 1  10.4243219
> 2  2NA
> 3  40.7094532
> 4  70.9630027
> 5  8NA
> 6  90.1218458
> 7 100.9183175
> 8 11NA
> 9 12NA
>
> xIdx <- match(x$id,y$id) yields a vector of length x, so it cannot be
> used directly to copy to y.
>
> Any help in vectorizing this assignment would be most welcome.
>
> Chris
>
> This e-mail, including attachments, may include confidential and/or
> proprietary information, and may be used only by the person or entity
> to which it is addressed. If the reader of this e-mail is not the intended
> recipient or his or her authorized agent, the reader is hereby notified
> that any dissemination, distribution or copying of this e-mail is
> prohibited. If you have received this e-mail in error, please notify the
> sender by replying to this message and delete this e-mail immediately.
>
> __
> R-help@r-project.org mailing list
> 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 code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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 code.


[R] match and as.character truncation

2008-08-01 Thread Eric Weese
I know the following is documented behaviour, in the sense that the  
help page for as.character mentions  that it truncates at about 500  
characters... but wouldn't it be better if there was a warning of  
some sort issued?  Or am I misunderstanding what's happening here?


> str <- sample(LETTERS,301, replace=TRUE)
> search.list <- list(str[-301],str)
> item <- list(str)# == search.list[2]
> match(item, search.list)
[1] 1
> item <- list(str[1:299])
> match(item, search.list)
[1] 1
> item <- list(str[1:29])
> match(item, search.list)
[1] NA
> version$version.string
[1] "R version 2.7.1 (2008-06-23)"

Thanks.



-Eric Weese
PhD candidate, Economics
MIT

__
R-help@r-project.org mailing list
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 code.


[R] match problem by rownames

2008-09-08 Thread Xianming Wei
Hi all,

While dat['a1',] and dat['a10',] produce the same results in the
following example, I'd like dat['a1',] to return NAs.

dat <- data.frame(x1 = paste(letters[1:5],10, sep=''), x2=rnorm(5))
rownames(dat) <- dat$x1
dat['a1',]
dat['a10',]

> sessionInfo()
R version 2.7.2 (2008-08-25)
i386-pc-mingw32

locale:
LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MON
ETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252

attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base


other attached packages:
[1] lattice_0.17-13

loaded via a namespace (and not attached):
[1] grid_2.7.2
>

Regards,
Xianming



DISCLAIMER:\ For details of our e-mail disclaimer, pleas...{{dropped:15}}

__
R-help@r-project.org mailing list
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 code.


Re: [R] match and incomparables

2008-09-12 Thread Adam D. I. Kramer

I can replicate this and also do not understand it.


match(1:3,1:3,incomparables=5)

[1] NA  2  3

match(1:3,1:3,incomparables=4)

[1] 1 2 3

match(1:3,1:3,incomparables=3)

[1] 1 2 3

match(1:3,1:3,incomparables=2)

[1] 1 2 3

match(1:3,1:3,incomparables=1)

[1] NA  2  3

...every other integer value for incomparables produces 1 2 and 3 for
output. I'm using R 2.7.2, self-compiled, under linux.

--Adam

On Fri, 12 Sep 2008, McGehee, Robert wrote:


Hello,
I was playing around with the newly implemented 'incomparables' argument
in 'match' and realized the argument does not behave anything like I
expected. Can someone explain what is going on here? Sorry if I'm
misreading the documentation.


match(1:3, 1:3, incomparables=1)

[1] NA  2  3  # This seems right, the 1 in 'x' is 'incomparable'


match(1:3, 1:3, incomparables=2)

[1] 1  2  3   # Shouldn't this be 1 NA 3? Why isn't the 2 incomparable?


match(1:3, 1:3, incomparables=5)

[1] NA  2  3   # Why isn't the 5 ignored?

Note from ?match:
"incomparables: a vector of values that cannot be matched. Any value in
x matching a value in this vector is assigned the nomatch value. For
historical reasons, FALSE is equivalent to NULL."

Thanks in advance!
Robert

platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  7.2
year   2008
month  08
day25
svn rev46428
language   R
version.string R version 2.7.2 (2008-08-25)

Robert McGehee, CFA
Geode Capital Management, LLC
One Post Office Square, 28th Floor | Boston, MA | 02109
Tel: 617/392-8396Fax:617/476-6389
mailto:[EMAIL PROTECTED]



This e-mail, and any attachments hereto, are intended fo...{{dropped:12}}

__
R-help@r-project.org mailing list
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 code.



__
R-help@r-project.org mailing list
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 code.


Re: [R] match and incomparables

2008-09-12 Thread Bert Gunter
Looks like a bug to me. Compare:

> match (1:3,1:3,incom=3)
[1] 1 2 3
> match (1:3,1:3,incom=2:3)
[1] 1 2 3
> match (1:3,1:3,incom=1:2)
[1] NA NA  3
> match (1:3,1:3,incom=1)
[1] NA  2  3

Cheers,
Bert


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Adam D. I. Kramer
Sent: Friday, September 12, 2008 3:06 PM
To: McGehee, Robert
Cc: r-help
Subject: Re: [R] match and incomparables

I can replicate this and also do not understand it.

> match(1:3,1:3,incomparables=5)
[1] NA  2  3
> match(1:3,1:3,incomparables=4)
[1] 1 2 3
> match(1:3,1:3,incomparables=3)
[1] 1 2 3
> match(1:3,1:3,incomparables=2)
[1] 1 2 3
> match(1:3,1:3,incomparables=1)
[1] NA  2  3

...every other integer value for incomparables produces 1 2 and 3 for
output. I'm using R 2.7.2, self-compiled, under linux.

--Adam

On Fri, 12 Sep 2008, McGehee, Robert wrote:

> Hello,
> I was playing around with the newly implemented 'incomparables' argument
> in 'match' and realized the argument does not behave anything like I
> expected. Can someone explain what is going on here? Sorry if I'm
> misreading the documentation.
>
>> match(1:3, 1:3, incomparables=1)
> [1] NA  2  3  # This seems right, the 1 in 'x' is 'incomparable'
>
>> match(1:3, 1:3, incomparables=2)
> [1] 1  2  3   # Shouldn't this be 1 NA 3? Why isn't the 2 incomparable?
>
>> match(1:3, 1:3, incomparables=5)
> [1] NA  2  3   # Why isn't the 5 ignored?
>
> Note from ?match:
> "incomparables: a vector of values that cannot be matched. Any value in
> x matching a value in this vector is assigned the nomatch value. For
> historical reasons, FALSE is equivalent to NULL."
>
> Thanks in advance!
> Robert
>
> platform   i386-pc-mingw32
> arch   i386
> os mingw32
> system i386, mingw32
> status
> major  2
> minor  7.2
> year   2008
> month  08
> day25
> svn rev46428
> language   R
> version.string R version 2.7.2 (2008-08-25)
>
> Robert McGehee, CFA
> Geode Capital Management, LLC
> One Post Office Square, 28th Floor | Boston, MA | 02109
> Tel: 617/392-8396Fax:617/476-6389
> mailto:[EMAIL PROTECTED]
>
>
>
> This e-mail, and any attachments hereto, are intended fo...{{dropped:12}}
>
> __
> R-help@r-project.org mailing list
> 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 code.
>

__
R-help@r-project.org mailing list
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 code.

__
R-help@r-project.org mailing list
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 code.


Re: [R] match and incomparables

2008-09-12 Thread Prof Brian Ripley

On Fri, 12 Sep 2008, Bert Gunter wrote:


Looks like a bug to me. Compare:


A bug fixed in the R-devel version of R (because of a related problem with 
duplicated).



match (1:3,1:3,incom=3)

[1] 1 2 3

match (1:3,1:3,incom=2:3)

[1] 1 2 3

match (1:3,1:3,incom=1:2)

[1] NA NA  3

match (1:3,1:3,incom=1)

[1] NA  2  3

Cheers,
Bert


-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of Adam D. I. Kramer
Sent: Friday, September 12, 2008 3:06 PM
To: McGehee, Robert
Cc: r-help
Subject: Re: [R] match and incomparables

I can replicate this and also do not understand it.


match(1:3,1:3,incomparables=5)

[1] NA  2  3

match(1:3,1:3,incomparables=4)

[1] 1 2 3

match(1:3,1:3,incomparables=3)

[1] 1 2 3

match(1:3,1:3,incomparables=2)

[1] 1 2 3

match(1:3,1:3,incomparables=1)

[1] NA  2  3

...every other integer value for incomparables produces 1 2 and 3 for
output. I'm using R 2.7.2, self-compiled, under linux.

--Adam

On Fri, 12 Sep 2008, McGehee, Robert wrote:


Hello,
I was playing around with the newly implemented 'incomparables' argument
in 'match' and realized the argument does not behave anything like I
expected. Can someone explain what is going on here? Sorry if I'm
misreading the documentation.


match(1:3, 1:3, incomparables=1)

[1] NA  2  3  # This seems right, the 1 in 'x' is 'incomparable'


match(1:3, 1:3, incomparables=2)

[1] 1  2  3   # Shouldn't this be 1 NA 3? Why isn't the 2 incomparable?


match(1:3, 1:3, incomparables=5)

[1] NA  2  3   # Why isn't the 5 ignored?

Note from ?match:
"incomparables: a vector of values that cannot be matched. Any value in
x matching a value in this vector is assigned the nomatch value. For
historical reasons, FALSE is equivalent to NULL."

Thanks in advance!
Robert

platform   i386-pc-mingw32
arch   i386
os mingw32
system i386, mingw32
status
major  2
minor  7.2
year   2008
month  08
day25
svn rev46428
language   R
version.string R version 2.7.2 (2008-08-25)

Robert McGehee, CFA
Geode Capital Management, LLC
One Post Office Square, 28th Floor | Boston, MA | 02109
Tel: 617/392-8396Fax:617/476-6389
mailto:[EMAIL PROTECTED]



This e-mail, and any attachments hereto, are intended fo...{{dropped:12}}

__
R-help@r-project.org mailing list
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 code.



__
R-help@r-project.org mailing list
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 code.

__
R-help@r-project.org mailing list
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 code.



--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
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 code.


Re: [R] match problem by rownames

2008-09-09 Thread Charilaos Skiadas

As suggested in ?"[.data.frame", try:

dat[match('a1', rownames(dat)),]


Haris Skiadas
Department of Mathematics and Computer Science
Hanover College

On Sep 9, 2008, at 2:41 AM, Xianming Wei wrote:


Hi all,

While dat['a1',] and dat['a10',] produce the same results in the
following example, I'd like dat['a1',] to return NAs.

dat <- data.frame(x1 = paste(letters[1:5],10, sep=''), x2=rnorm(5))
rownames(dat) <- dat$x1
dat['a1',]
dat['a10',]


sessionInfo()

R version 2.7.2 (2008-08-25)
i386-pc-mingw32

locale:
LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia. 
1252;LC_MON
ETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia. 
1252


attached base packages:
[1] stats graphics  grDevices utils datasets  methods   base


other attached packages:
[1] lattice_0.17-13

loaded via a namespace (and not attached):
[1] grid_2.7.2




Regards,
Xianming



__
R-help@r-project.org mailing list
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 code.


Re: [R] match problem by rownames

2008-09-09 Thread Dimitris Rizopoulos
try this:

dat <- data.frame(x1 = paste(letters[1:5],10, sep=''), x2=rnorm(5))
row.names(dat) <- dat$x1

dat['a1' %in% row.names(dat), ]
dat['a10'  %in% row.names(dat), ]


I hope it helps.

Best,
Dimitris


> Hi all,
>
> While dat['a1',] and dat['a10',] produce the same results in the
> following example, I'd like dat['a1',] to return NAs.
>
> dat <- data.frame(x1 = paste(letters[1:5],10, sep=''), x2=rnorm(5))
> rownames(dat) <- dat$x1
> dat['a1',]
> dat['a10',]
>
>> sessionInfo()
> R version 2.7.2 (2008-08-25)
> i386-pc-mingw32
>
> locale:
> LC_COLLATE=English_Australia.1252;LC_CTYPE=English_Australia.1252;LC_MON
> ETARY=English_Australia.1252;LC_NUMERIC=C;LC_TIME=English_Australia.1252
>
> attached base packages:
> [1] stats graphics  grDevices utils datasets  methods   base
>
>
> other attached packages:
> [1] lattice_0.17-13
>
> loaded via a namespace (and not attached):
> [1] grid_2.7.2
>>
>
> Regards,
> Xianming
>
>
>
> DISCLAIMER:\ For details of our e-mail disclaimer, pleas...{{dropped:15}}
>
> __
> R-help@r-project.org mailing list
> 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 code.
>


-- 
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center

Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043399
Fax: +31/(0)10/7044657

__
R-help@r-project.org mailing list
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 code.


[R] Match and replace between two data.frames

2007-10-24 Thread Lauri Nikkinen
Hi folks,

I have two dataframes like these:

DF <- data.frame(ID=c("AA1234","AB3233","AC4353","AD2345","AE7453"),
CK32344=c(1,3,2,4,1), CK32664=c(2,1,1,2,3), CK33422=c(2,2,1,3,2))
VAL <- data.frame(num=rep(6,3), type=c("CK32344", "CK32664",
"CK33422"), number=c("32","452","234"))

I want to replace the values in DF$CK32344, DF$CK32664 DF$CK33422 with
the corresponding number in the VAL$number.

The results should look like this:

RES <- data.frame(ID=c("AA1234","AB3233","AC4353","AD2345","AE7453"),
CK32344=rep(32, 5), CK32664=rep(425, 5), CK33422=rep(234, 5))

How do I do that?

Regards,
Lauri

__
R-help@r-project.org mailing list
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 code.


Re: [R] Match and replace between two data.frames

2007-10-25 Thread Henrique Dallazuanna
HI,

Perhaps:

cbind(ID=DF$ID,as.data.frame(sapply(levels(VAL$type),
function(x){DF[,x]=VAL$number[VAL$type==x];DF[,x]})))


On 25/10/2007, Lauri Nikkinen <[EMAIL PROTECTED]> wrote:
>
> Hi folks,
>
> I have two dataframes like these:
>
> DF <- data.frame(ID=c("AA1234","AB3233","AC4353","AD2345","AE7453"),
> CK32344=c(1,3,2,4,1), CK32664=c(2,1,1,2,3), CK33422=c(2,2,1,3,2))
> VAL <- data.frame(num=rep(6,3), type=c("CK32344", "CK32664",
> "CK33422"), number=c("32","452","234"))
>
> I want to replace the values in DF$CK32344, DF$CK32664 DF$CK33422 with
> the corresponding number in the VAL$number.
>
> The results should look like this:
>
> RES <- data.frame(ID=c("AA1234","AB3233","AC4353","AD2345","AE7453"),
> CK32344=rep(32, 5), CK32664=rep(425, 5), CK33422=rep(234, 5))
>
> How do I do that?
>
> Regards,
> Lauri
>
> __
> R-help@r-project.org mailing list
> 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 code.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
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 code.