Re: [R] vector

2008-12-01 Thread David Winsemius


> pop<-c(1,5,14,7,9,12,18,19,65,54)


> samp <- sample(pop, 2, replace=FALSE)
> samp
[1] 14  9
> pop2<- pop[!pop %in% samp]
> pop2
[1]  1  5  7 12 18 19 65 54


On Dec 1, 2008, at 2:29 PM, Hamid Hamid wrote:


Dear All,
I am trying to build a program which will take repeated samples  
without
replacement from a population of values. The interesting catch is  
that I
would like the sample values to be removed from the population,  
after each

sample is taken.

For example:

pop<-c(1,5,14,7,9,12,18,19,65,54)


sample(pop, 2) = lets say, (5,54)
## This is where I would like values (5, 54) to be removed from the
population vector, giving a new "current" population vector:


"new" pop = [1,14,7,9,12,18,19,65]
and has length 8 instead of 10.

In the cases when the size of pop and deriven sample of it is enough  
large

using the following command is not helpful.
newpop<-pop[-c(2,10)]

One could simplify my question in this way: how we can exclude a sub  
vector
values from a super  vector value (i.e sub vecor values are subset  
of super

vector values).
Thanks in advance.
Hamid

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

2008-12-01 Thread Charles C. Berry

On Mon, 1 Dec 2008, Hamid Hamid wrote:


Dear All,
I am trying to build a program which will take repeated samples without
replacement from a population of values. The interesting catch is that I
would like the sample values to be removed from the population, after each
sample is taken.


You mean ONLY 'after each sample is taken'? That is,  you sample with 
replacement, then remove the sample from the population, sample again with 
replacement and then remove those, ...


If that is not what you mean, ordinary sampling WOR will do.

If the scheme I describe above is what you meant, read on.

Sometimes it is efficient to vectorize in a way that yields an incomplete 
answer, then patch the result, then patch the patched result, ...


Here is an example that implements drawing samples with replacement, but 
removing each sample before drawing the next (so a single sample could 
contain duplicates, but no pair of samples could contain the same 
element):



n <- c(3,3,4) # draw samples of size n[i]
samp <- rep(seq(n),n) # index the sample
trials <- sample(pop,sum(n),repl=TRUE) # fast but not always right
index.first.like.me <- match(trials,trials)
gotta.fix <- which( samp[ index.first.like.me ] < samp )
trials[ gotta.fix ] <- sample( setdiff(pop,trials), length( gotta.fix ), 
repl=TRUE )
index.first.like.me <- match(trials,trials)
gotta.fix <- which( samp[ index.first.like.me ] < samp )
length(gotta.fix) # see if there are any cases to fix

[1] 0




Obviously, you would build the part after the 'trials <-' line  into a 
while(){} loop , and you can easily improve upon 'setdiff( pop, trials )'.


HTH,

Chuck




For example:

pop<-c(1,5,14,7,9,12,18,19,65,54)


sample(pop, 2) = lets say, (5,54)
## This is where I would like values (5, 54) to be removed from the
population vector, giving a new "current" population vector:


"new" pop = [1,14,7,9,12,18,19,65]
and has length 8 instead of 10.

In the cases when the size of pop and deriven sample of it is enough large
using the following command is not helpful.
newpop<-pop[-c(2,10)]

One could simplify my question in this way: how we can exclude a sub vector
values from a super  vector value (i.e sub vecor values are subset of super
vector values).
Thanks in advance.
Hamid

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



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
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] vector

2009-07-29 Thread Linlin Yan
rep(A, each=2)

On Thu, Jul 30, 2009 at 12:15 AM, Inchallah
Yarab wrote:
> Hi ,
>
> i have a vector A=(a1,a2,a3,a4) and i want to create another vector 
> B=(a1,a1,a2,a2,a3,a3,a4,a4) !!!
> i know that it is simple but i begin with R so i nned your help!!
>
> thank you for your help !!!
>
>
>
>        [[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-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] vector help

2008-07-21 Thread Henrique Dallazuanna
Try:

paste(test, collapse='-')


On Mon, Jul 21, 2008 at 3:49 PM, Rajasekaramya <[EMAIL PROTECTED]> wrote:
>
> hi
>
> I have vector test. It has 3 elements. I want to join the three into one
> vector.
> "Geneset=HSA04910_INSULIN_SIGNALING_PATHWAY-157- 20".
> how can i do it.
>
>
>
>> class(test)
> [1] "character"
>> test
> [1] "Geneset=HSA04910_INSULIN_SIGNALING_PATHWAY" "157"
> [3] "20"
>
> Ramya
> --
> View this message in context: 
> http://www.nabble.com/vector-help-tp18575055p18575055.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.
>



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

__
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] vector help

2008-07-21 Thread Jorge Ivan Velez
Try this:

test=c("Geneset=HSA04910_INSULIN_SIGNALING_PATHWAY","157","20")
paste(test, collapse="-",sep="")

HTH,

Jorge


On Mon, Jul 21, 2008 at 2:49 PM, Rajasekaramya <[EMAIL PROTECTED]>
wrote:

>
> hi
>
> I have vector test. It has 3 elements. I want to join the three into one
> vector.
> "Geneset=HSA04910_INSULIN_SIGNALING_PATHWAY-157- 20".
> how can i do it.
>
>
>
> > class(test)
> [1] "character"
> > test
> [1] "Geneset=HSA04910_INSULIN_SIGNALING_PATHWAY" "157"
> [3] "20"
>
> Ramya
> --
> View this message in context:
> http://www.nabble.com/vector-help-tp18575055p18575055.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.
>

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


Re: [R] vector help

2008-07-21 Thread Dimitris Rizopoulos

try this:

paste(test, collapse = "-")


Best,
Dimitris


Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://perswww.kuleuven.be/dimitris_rizopoulos/


Quoting Rajasekaramya <[EMAIL PROTECTED]>:



hi

I have vector test. It has 3 elements. I want to join the three into one
vector.
"Geneset=HSA04910_INSULIN_SIGNALING_PATHWAY-157- 20".
how can i do it.




class(test)

[1] "character"

test

[1] "Geneset=HSA04910_INSULIN_SIGNALING_PATHWAY" "157"
[3] "20"

Ramya
--
View this message in context:   
http://www.nabble.com/vector-help-tp18575055p18575055.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.






Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
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] vector distribution

2007-12-24 Thread Ben Bolker
-Halcyon-  gmail.com> writes:

> 
> 
> Hi everyone, 
> 
> say i have a population (stable) with different amounts of animals in every
> ageclass (80 of age 1, 60 of age 2, etc) in a vector.
> Can anybody tell me how i can add gender (male or female) to all ageclasses?
> I want a 1:1 ratio of males and females within the population (as a starting
> value). So, 40 males and 40 females of age 1, 30m-30f of age 2, etc etc... 
> 
> Any help would be greatly appreciated!! 
> 
> Kind regards

  Do you mean something like

> x <- c(age1=80,age2=60,age3=40)
> x
age1 age2 age3 
  80   60   40 
> y <- rep(x/2,2)
> names(y) <- c(paste("M",names(x),sep="."),paste("F",names(x),sep="."))
> y
M.age1 M.age2 M.age3 F.age1 F.age2 F.age3 
40 30 20 40 30 20 
> 

  ?

  Ben Bolker

__
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] vector generation

2008-01-17 Thread Gabor Csardi
See ?outer

outer(Z, Z, function(x,y) x/y)

Gabor

On Thu, Jan 17, 2008 at 01:24:33PM -0300, Juan Pablo Fededa wrote:
> Dear Contributors:
> 
> I have the next vector:
> 
> "Z"
> 
> 526
> 723
> 110
> 1110
> 34
> 778
> 614
> 249
> 14
> 
> I want to generate a vector containing the ratios of all the values
> versus all the values of the z vector. I mean a vector containing the
> values of 526/723, 526/110, and so on, 723/723, 723/110, and so on,
> and so on.
> Is this doable in a simple way??
> Thanks in advance again,
> 
> 
> 
> Juan Pablo Fededa
> 
> __
> 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.

-- 
Csardi Gabor <[EMAIL PROTECTED]>UNIL DGM

__
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] vector generation

2008-01-24 Thread Albert Greinoecker
 z[z > 1]

regards,
Albert

Am Donnerstag, den 24.01.2008, 10:54 -0300 schrieb Juan Pablo Fededa:
> Dear Contributors:
> 
> I have the next vector:
> 
> "Z"
> 
> z = (526, 0.1, 110, 0.2, 34, 0.4, 614, 0.5, 1, 14, 15)
> 
> 
> I want to generate a vector containing the values higher than 1
> corresponding to the z vector, wich in this case will mean to generate the
> next vector:
> 
> (526, 110, 34, 614, 14, 15)
> 
> 
> If you have any clue on how to do that, I will be very glad to hear it!!
> Thanks in advance again,
> 
>   [[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-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] vector comparison

2008-06-05 Thread jim holtman
This may help:

> a <- c('a')
> b <- c('a','b','c')
> c <- c('a','b','d')
> all(a %in% b)
[1] TRUE
> all(b %in% a)
[1] FALSE
> all(b %in% c)
[1] FALSE
> d <- c('b', 'c')
> all(d %in% b)
[1] TRUE
>

What you probably want to insure that the vectors contain the same elements
is:

if (all(v1 %in$ v2) && all(v2 %in% v1))




On Thu, Jun 5, 2008 at 6:38 AM, Karin Lagesen <[EMAIL PROTECTED]>
wrote:

>
> I know this is fairly basic, but I must have somehow missed it in the
> manuals.
>
> I have two vectors, often of unequal length. I would like to compare
> them for identity. Order of elements do not matter, but they should
> contain the same.
>
> I.e: I want this kind of comparison:
>
> > if (1==1) show("yes") else show("blah")
> [1] "yes"
> > if (1==2) show("yes") else show("blah")
> [1] "blah"
> >
>
> Only replace the numbers with for instance the vectors
>
> > a = c("a")
> > b = c("b","c")
> > c = c("c","b")
>
>
> Now, I realize I only get a warning when comparing things, but this to
> me means that I am not doing it correctly:
>
> > if (a==a) show("yes") else show("blah")
> [1] "yes"
> > if (a==b) show("yes") else show("blah")
> [1] "blah"
> Warning message:
> In if (a == b) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
> > if (b == c) show("yes") else show("blah")
> [1] "blah"
> Warning message:
> In if (b == c) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
>
> I have also tried the %in% comparator, but that one throws warnings too:
>
> > if (b %in% c) show("yes") else show("blah")
> [1] "yes"
> Warning message:
> In if (b %in% c) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
> > if (c %in% c) show("yes") else show("blah")
> [1] "yes"
> Warning message:
> In if (c %in% c) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
>
> So, how is this really supposed to be done?
>
> Thanks!
>
> Karin
>
> __
> 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?

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


Re: [R] vector comparison

2008-06-05 Thread Dimitris Rizopoulos

probably you want to look at:

?any
?all


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
http://www.student.kuleuven.be/~m0390867/dimitris.htm


- Original Message - 
From: "Karin Lagesen" <[EMAIL PROTECTED]>

To: 
Sent: Thursday, June 05, 2008 12:38 PM
Subject: [R] vector comparison




I know this is fairly basic, but I must have somehow missed it in 
the

manuals.

I have two vectors, often of unequal length. I would like to compare
them for identity. Order of elements do not matter, but they should
contain the same.

I.e: I want this kind of comparison:


if (1==1) show("yes") else show("blah")

[1] "yes"

if (1==2) show("yes") else show("blah")

[1] "blah"




Only replace the numbers with for instance the vectors


a = c("a")
b = c("b","c")
c = c("c","b")



Now, I realize I only get a warning when comparing things, but this 
to

me means that I am not doing it correctly:


if (a==a) show("yes") else show("blah")

[1] "yes"

if (a==b) show("yes") else show("blah")

[1] "blah"
Warning message:
In if (a == b) show("yes") else show("blah") :
 the condition has length > 1 and only the first element will be 
used


if (b == c) show("yes") else show("blah")

[1] "blah"
Warning message:
In if (b == c) show("yes") else show("blah") :
 the condition has length > 1 and only the first element will be 
used




I have also tried the %in% comparator, but that one throws warnings 
too:



if (b %in% c) show("yes") else show("blah")

[1] "yes"
Warning message:
In if (b %in% c) show("yes") else show("blah") :
 the condition has length > 1 and only the first element will be 
used


if (c %in% c) show("yes") else show("blah")

[1] "yes"
Warning message:
In if (c %in% c) show("yes") else show("blah") :
 the condition has length > 1 and only the first element will be 
used




So, how is this really supposed to be done?

Thanks!

Karin

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




Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
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] vector comparison

2008-06-05 Thread Chuck Cleland

On 6/5/2008 6:38 AM, Karin Lagesen wrote:

I know this is fairly basic, but I must have somehow missed it in the
manuals.

I have two vectors, often of unequal length. I would like to compare
them for identity. Order of elements do not matter, but they should
contain the same.

I.e: I want this kind of comparison:


if (1==1) show("yes") else show("blah")

[1] "yes"

if (1==2) show("yes") else show("blah")

[1] "blah"

Only replace the numbers with for instance the vectors 


a = c("a")
b = c("b","c")
c = c("c","b")



Now, I realize I only get a warning when comparing things, but this to
me means that I am not doing it correctly:


if (a==a) show("yes") else show("blah")

[1] "yes"

if (a==b) show("yes") else show("blah")

[1] "blah"
Warning message:
In if (a == b) show("yes") else show("blah") :
  the condition has length > 1 and only the first element will be used

if (b == c) show("yes") else show("blah")

[1] "blah"
Warning message:
In if (b == c) show("yes") else show("blah") :
  the condition has length > 1 and only the first element will be used

I have also tried the %in% comparator, but that one throws warnings too:


if (b %in% c) show("yes") else show("blah")

[1] "yes"
Warning message:
In if (b %in% c) show("yes") else show("blah") :
  the condition has length > 1 and only the first element will be used

if (c %in% c) show("yes") else show("blah")

[1] "yes"
Warning message:
In if (c %in% c) show("yes") else show("blah") :
  the condition has length > 1 and only the first element will be used

So, how is this really supposed to be done?


a <- c("a")
b <- c("b","c")
c <- c("c","b")

if (setequal(a, b)) show("yes") else show("blah")
[1] "blah"

if (setequal(a, c)) show("yes") else show("blah")
[1] "blah"

if (setequal(b, c)) show("yes") else show("blah")
[1] "yes"

?setequal


Thanks!

Karin

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


--
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
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] vector comparison

2008-06-05 Thread Michael Prince
Hello Karin

This is your code :

a = c("a")
b = c("b","c")
c = c("c","b")
if (a==a) show("yes") else show("blah")
if (a==b) show("yes") else show("blah")
if (b==c) show("yes") else show("blah")

Have a look at the conditions (a==b) and (b==c)

> a==b
[1] FALSE FALSE
> b==c
[1] FALSE FALSE

They are size 2.
I think R takes the first logical value. That's why you get the warning.

I hope this helps.

2008/6/5 Karin Lagesen <[EMAIL PROTECTED]>:

>
> I know this is fairly basic, but I must have somehow missed it in the
> manuals.
>
> I have two vectors, often of unequal length. I would like to compare
> them for identity. Order of elements do not matter, but they should
> contain the same.
>
> I.e: I want this kind of comparison:
>
> > if (1==1) show("yes") else show("blah")
> [1] "yes"
> > if (1==2) show("yes") else show("blah")
> [1] "blah"
> >
>
> Only replace the numbers with for instance the vectors
>
> > a = c("a")
> > b = c("b","c")
> > c = c("c","b")
>
>
> Now, I realize I only get a warning when comparing things, but this to
> me means that I am not doing it correctly:
>
> > if (a==a) show("yes") else show("blah")
> [1] "yes"
> > if (a==b) show("yes") else show("blah")
> [1] "blah"
> Warning message:
> In if (a == b) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
> > if (b == c) show("yes") else show("blah")
> [1] "blah"
> Warning message:
> In if (b == c) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
>
> I have also tried the %in% comparator, but that one throws warnings too:
>
> > if (b %in% c) show("yes") else show("blah")
> [1] "yes"
> Warning message:
> In if (b %in% c) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
> > if (c %in% c) show("yes") else show("blah")
> [1] "yes"
> Warning message:
> In if (c %in% c) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
>
> So, how is this really supposed to be done?
>
> Thanks!
>
> Karin
>
> __
> 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.


Re: [R] vector comparison

2008-06-05 Thread Bert Gunter
.. or identical(sort(unique(a)),sort(unique(b)))

-- Bert Gunter
Genentech Nonclinical Statistics



-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On
Behalf Of jim holtman
Sent: Thursday, June 05, 2008 5:01 AM
To: Karin Lagesen
Cc: r-help@r-project.org
Subject: Re: [R] vector comparison

This may help:

> a <- c('a')
> b <- c('a','b','c')
> c <- c('a','b','d')
> all(a %in% b)
[1] TRUE
> all(b %in% a)
[1] FALSE
> all(b %in% c)
[1] FALSE
> d <- c('b', 'c')
> all(d %in% b)
[1] TRUE
>

What you probably want to insure that the vectors contain the same elements
is:

if (all(v1 %in$ v2) && all(v2 %in% v1))




On Thu, Jun 5, 2008 at 6:38 AM, Karin Lagesen <[EMAIL PROTECTED]>
wrote:

>
> I know this is fairly basic, but I must have somehow missed it in the
> manuals.
>
> I have two vectors, often of unequal length. I would like to compare
> them for identity. Order of elements do not matter, but they should
> contain the same.
>
> I.e: I want this kind of comparison:
>
> > if (1==1) show("yes") else show("blah")
> [1] "yes"
> > if (1==2) show("yes") else show("blah")
> [1] "blah"
> >
>
> Only replace the numbers with for instance the vectors
>
> > a = c("a")
> > b = c("b","c")
> > c = c("c","b")
>
>
> Now, I realize I only get a warning when comparing things, but this to
> me means that I am not doing it correctly:
>
> > if (a==a) show("yes") else show("blah")
> [1] "yes"
> > if (a==b) show("yes") else show("blah")
> [1] "blah"
> Warning message:
> In if (a == b) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
> > if (b == c) show("yes") else show("blah")
> [1] "blah"
> Warning message:
> In if (b == c) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
>
> I have also tried the %in% comparator, but that one throws warnings too:
>
> > if (b %in% c) show("yes") else show("blah")
> [1] "yes"
> Warning message:
> In if (b %in% c) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
> > if (c %in% c) show("yes") else show("blah")
> [1] "yes"
> Warning message:
> In if (c %in% c) show("yes") else show("blah") :
>  the condition has length > 1 and only the first element will be used
> >
>
> So, how is this really supposed to be done?
>
> Thanks!
>
> Karin
>
> __
> 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<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?

[[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-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] vector comparison

2008-06-06 Thread Jim Lemon

Karin Lagesen wrote:

I know this is fairly basic, but I must have somehow missed it in the
manuals.

I have two vectors, often of unequal length. I would like to compare
them for identity. Order of elements do not matter, but they should
contain the same.

I.e: I want this kind of comparison:



if (1==1) show("yes") else show("blah")


[1] "yes"


if (1==2) show("yes") else show("blah")


[1] "blah"


Only replace the numbers with for instance the vectors 




a = c("a")
b = c("b","c")
c = c("c","b")




Now, I realize I only get a warning when comparing things, but this to
me means that I am not doing it correctly:



if (a==a) show("yes") else show("blah")


[1] "yes"


if (a==b) show("yes") else show("blah")


[1] "blah"
Warning message:
In if (a == b) show("yes") else show("blah") :
  the condition has length > 1 and only the first element will be used


if (b == c) show("yes") else show("blah")


[1] "blah"
Warning message:
In if (b == c) show("yes") else show("blah") :
  the condition has length > 1 and only the first element will be used


I have also tried the %in% comparator, but that one throws warnings too:



if (b %in% c) show("yes") else show("blah")


[1] "yes"
Warning message:
In if (b %in% c) show("yes") else show("blah") :
  the condition has length > 1 and only the first element will be used


if (c %in% c) show("yes") else show("blah")


[1] "yes"
Warning message:
In if (c %in% c) show("yes") else show("blah") :
  the condition has length > 1 and only the first element will be used


So, how is this really supposed to be done?


Hi Karin,
My interpretation of your question is that you want to test whether two 
vectors contain the same elements, whether or not the order of those 
elements is the same. I'll first assume that the vectors must only have 
elements from the same _set_ and it doesn't matter if they have 
different lengths.


if(length(unique(a))==length(unique(b))) {
 if(all(unique(a)==unique(b))) cat("Yes\n")
 else cat("No\n")
}
else cat("No\n")

However, if the lengths must be the same, but the order may be different:

if(length(a)==length(b)) {
 if(all(sort(a)==sort(b))) cat("Yes\n")
 else cat("No\n")
}
else cat("No\n")

The latter test ensures that if there are repeated elements, the number 
of repeats of each element is the same in each vector.


Jim

__
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] Vector loop

2008-02-05 Thread jim holtman
Not too sure of exactly what you want to do with the loop.  Here is
one that prints out the values:

> x <- 1:10
> for (i in x) print(i)
[1] 1
[1] 2
[1] 3
[1] 4
[1] 5
[1] 6
[1] 7
[1] 8
[1] 9
[1] 10
>


On 2/5/08, mohamed nur anisah <[EMAIL PROTECTED]> wrote:
> hi,
>
>  I'm in my learning process of doing a programming with "for" loop. How to 
> make a loop of a vector of length 10 where elements are 1,2,3,4,5,6,7,8,9,10. 
> Any suggestion needed!! Many thanks.
>
>  Cheers,
>  Anisah
>
>
> -
>
>[[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.
>


-- 
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] Vector Size

2008-02-08 Thread jim holtman
How much memory do you have on your system?  What type of system do
you have?  There is information in the archive about generating a
sequence like this without having to have it all in memory at once.
BTW, your matrix will require 1GB to store a single copy, so you will
probably need at least 2-3X (2-3GB) to create it and do something with
it.

On Feb 8, 2008 7:28 PM, Oscar A <[EMAIL PROTECTED]> wrote:
>
> Hello everybody!!
> I'm from Colombia (South America) and I'm new on R.  I've been trying to
> generate all of the possible combinations for a 6 number combination with
> numbers that ranges from 1 to 53.
>
> I've used the following commands:
>
> datos<-c(1:53)
> M<-matrix(data=(combn(datos,6,FUN=NULL,simplify=TRUE)),nrow=22957480,ncol=6,byrow=TRUE)
>
> Once the commands are executed, the program shows the following:
>
> Error: CANNOT ALLOCATE A VECTOR OF SIZE 525.5 Mb
>
>
> How can I fix this problem?
> --
> View this message in context: 
> http://www.nabble.com/Vector-Size-tp15366901p15366901.html
> Sent from the R help mailing list archive at Nabble.com.
>
>[[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.
>



-- 
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] Vector Size

2008-02-10 Thread John Kane
You just have too large a vector for your memory.
There is not much you can do with an object of 500 MG.
 You have over 137 million combinations.

What are you trying to do with this vector?


--- Oscar A <[EMAIL PROTECTED]> wrote:

> 
> Hello everybody!!
> I'm from Colombia (South America) and I'm new on R. 
> I've been trying to
> generate all of the possible combinations for a 6
> number combination with
> numbers that ranges from 1 to 53.
> 
> I've used the following commands:
> 
> datos<-c(1:53)
>
M<-matrix(data=(combn(datos,6,FUN=NULL,simplify=TRUE)),nrow=22957480,ncol=6,byrow=TRUE)
> 
> Once the commands are executed, the program shows
> the following:
> 
> Error: CANNOT ALLOCATE A VECTOR OF SIZE 525.5 Mb
> 
> 
> How can I fix this problem?
> -- 
> View this message in context:
>
http://www.nabble.com/Vector-Size-tp15366901p15366901.html
> Sent from the R help mailing list archive at
> Nabble.com.
> 
>   [[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-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] vector manipulations

2008-03-04 Thread Erik Iverson
Did you read the help page for 'outer'?

?outer

It says

  'FUN' is called with these two extended vectors as arguments.
  Therefore, it must be a vectorized function (or the name of one),
  expecting at least two arguments.


I don't think your logl function is vectorized according to your summary 
of what you did.


Pete Dorothy wrote:
> Hello,
> 
> I have simulated a set of data which i called "nir" (a vector).
> 
> I have created a function "logl" which calculates the log-likelihood.
> 
> logl is a function of 2 real parameters : "beta" and "zeta" (of length 1).
> 
> This function works perfectly well when I try for example "logl(0.1,0.2)"
> 
> Now if I try :
> 
> "x=seq(0.1,0.5,by=10^(-1))
> y=seq(0.1,0.5,by=10^(-1))
> z=outer(x,y,logl)"
> 
> I get an error.
> 
> The problem seems to be that inside "logl", the following expression is
> calculated : "sum( log( beta+(nir-1)*zeta )  )". So it is a vector
> manipulation. The error tells me that "nir" is not the size of "zeta". Yet
> usually it is no problem since "length(zeta)=1".
> 
> When I replace "sum( log( beta+(nir-1)*zeta ) )" by a loop, I get no
> mistake. But I think it slows down the program.
> 
> Do you have an idea where the problem is ?
> 
> Thank you very much.
> 
>   [[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-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] vector manipulations

2008-03-04 Thread Pete Dorothy
Thank you very much to both of you, and especially you Phil.

I will tell you if it works.

2008/3/4, Phil Spector <[EMAIL PROTECTED]>:
>
> Pete -
> As others have told you, outer only works with vectorized
> functions.  An alternative is to use expand.grid to find all
> the combinations of beta and zeta, and then use apply to
> calculate your likelihood for each row.  I believe that this
> will work:
>
> allvals = expand.grid(beta=seq(0.1,0.5,by=10^(-1)),zeta=seq(0.1,0.5
> ,by=10^(-1)))
> answer = cbind(allvals,result =
> apply(allvals,1,function(x)logl(x[1],x[2])))
>
> The columns of answer will be named beta, zeta and result, with
> (hopefully) obvious meanings.
>
> - Phil Spector
>  Statistical Computing Facility
>  Department of Statistics
>  UC Berkeley
>  [EMAIL PROTECTED]
>
>
>
>
> On Tue, 4 Mar 2008, Pete Dorothy wrote:
>
> > Hello,
> >
> > I have simulated a set of data which i called "nir" (a vector).
> >
> > I have created a function "logl" which calculates the log-likelihood.
> >
> > logl is a function of 2 real parameters : "beta" and "zeta" (of length
> 1).
> >
> > This function works perfectly well when I try for example "logl(0.1,0.2
> )"
> >
> > Now if I try :
> >
> > "x=seq(0.1,0.5,by=10^(-1))
> > y=seq(0.1,0.5,by=10^(-1))
> > z=outer(x,y,logl)"
> >
> > I get an error.
> >
> > The problem seems to be that inside "logl", the following expression is
> > calculated : "sum( log( beta+(nir-1)*zeta )  )". So it is a vector
> > manipulation. The error tells me that "nir" is not the size of "zeta".
> Yet
> > usually it is no problem since "length(zeta)=1".
> >
> > When I replace "sum( log( beta+(nir-1)*zeta ) )" by a loop, I get no
> > mistake. But I think it slows down the program.
> >
> > Do you have an idea where the problem is ?
> >
> > Thank you very much.
> >
>
> >   [[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.
> >
>

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


Re: [R] vector manipulations

2008-03-04 Thread Bill.Venables
Your problem is that your function log1( , ) is not vectorized with
respect to its arguments.  For a function to work in outer(...) it must
accept vectors for its first two arguments and it must produce a
parallel vector of responses.  

To quote the help information for outer:

"FUN is called with these two extended vectors as arguments. Therefore,
it must be a vectorized function (or the name of one), expecting at
least two arguments."

Sometimes Vectorize can be used to make a non-vectorized function into a
vectorized one, but the results are not always entirely satisfactory in
my experience.  See

?Vectorize 


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile: +61 4 8819 4402
Home Phone: +61 7 3286 7700
mailto:[EMAIL PROTECTED]
http://www.cmis.csiro.au/bill.venables/ 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Pete Dorothy
Sent: Wednesday, 5 March 2008 3:38 AM
To: r-help@r-project.org
Subject: [R] vector manipulations

Hello,

I have simulated a set of data which i called "nir" (a vector).

I have created a function "logl" which calculates the log-likelihood.

logl is a function of 2 real parameters : "beta" and "zeta" (of length
1).

This function works perfectly well when I try for example
"logl(0.1,0.2)"

Now if I try :

x <- seq(0.1, 0.5, by = 0.1)
y <- seq(0.1, 0.5, by = 0.1)
z <- outer(x, y, logl)"

I get an error.

The problem seems to be that inside "logl", the following expression is
calculated : "sum( log( beta+(nir-1)*zeta )  )". So it is a vector
manipulation. The error tells me that "nir" is not the size of "zeta".
Yet
usually it is no problem since "length(zeta)=1".

When I replace "sum( log( beta+(nir-1)*zeta ) )" by a loop, I get no
mistake. But I think it slows down the program.

Do you have an idea where the problem is ?

Thank you very much.

[[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-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] vector manipulations

2008-03-04 Thread Duncan Murdoch
On 3/4/2008 5:41 PM, [EMAIL PROTECTED] wrote:
> Your problem is that your function log1( , ) is not vectorized with
> respect to its arguments.  For a function to work in outer(...) it must
> accept vectors for its first two arguments and it must produce a
> parallel vector of responses.  
> 
> To quote the help information for outer:
> 
> "FUN is called with these two extended vectors as arguments. Therefore,
> it must be a vectorized function (or the name of one), expecting at
> least two arguments."
> 
> Sometimes Vectorize can be used to make a non-vectorized function into a
> vectorized one, but the results are not always entirely satisfactory in
> my experience. 

What problems have you seen?

Duncan Murdoch

__
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] vector manipulations

2008-03-04 Thread Bill.Venables
No problems with it working.  The main problem I have observed is
unrealistic expectations.  People write an *essentially* non-vectorized
function and expect Vectorize to produce a version of it which will
out-perform explicit loops every time.  No magic bullets in this game.

Bill. 


Bill Venables
CSIRO Laboratories
PO Box 120, Cleveland, 4163
AUSTRALIA
Office Phone (email preferred): +61 7 3826 7251
Fax (if absolutely necessary):  +61 7 3826 7304
Mobile: +61 4 8819 4402
Home Phone: +61 7 3286 7700
mailto:[EMAIL PROTECTED]
http://www.cmis.csiro.au/bill.venables/ 

-Original Message-
From: Duncan Murdoch [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, 5 March 2008 9:36 AM
To: Venables, Bill (CMIS, Cleveland)
Cc: r-help@r-project.org
Subject: Re: [R] vector manipulations

On 3/4/2008 5:41 PM, [EMAIL PROTECTED] wrote:
> Your problem is that your function log1( , ) is not vectorized with
> respect to its arguments.  For a function to work in outer(...) it
must
> accept vectors for its first two arguments and it must produce a
> parallel vector of responses.  
> 
> To quote the help information for outer:
> 
> "FUN is called with these two extended vectors as arguments.
Therefore,
> it must be a vectorized function (or the name of one), expecting at
> least two arguments."
> 
> Sometimes Vectorize can be used to make a non-vectorized function into
a
> vectorized one, but the results are not always entirely satisfactory
in
> my experience. 

What problems have you seen?

Duncan Murdoch

__
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] vector manipulations

2008-03-05 Thread Pete Dorothy
Thank you everybody.

Phil, your expand.grid works very nicely and I will use it for
non-vectorized functions.

Yet I am a bit confused about "vectorization". For me it is synonymous of
"no loop". :-(

I wrote a toy example (with a function which is not my log-likelihood).

FIRST PART

nir=1:10
logl=function(x,y,nir) sum(log(x*nir+y))

x=seq(0.1,0.3,by=10^(-1))
y=seq(0.1,0.3,by=10^(-1))
z=outer(x,y,logl,nir=nir)

This does not work. Can you explain me why it is not "vectorised" ?

SECOND PART

nir=1:10
logl2=function(x,y,nir) {
a=0
for (i in 1:10) {
a=a+log(x*nir[i]+y)
}
return(a)
}

x=seq(0.1,0.3,by=10^(-1))
y=seq(0.1,0.3,by=10^(-1))
z2=outer(x,y,logl2,nir=nir)

This seems to work, though the function does not seem to be vectorized.

I am sorry for being such a noob. I'm ok in maths but I am bad at
programming. I bought a book on R (Introductory Statistics with R by
Dalgaard) ** on Amazon last week . I will read it when I receive it. Do you
know other good books ?

2008/3/5, [EMAIL PROTECTED] <[EMAIL PROTECTED]>:
>
> No problems with it working.  The main problem I have observed is
> unrealistic expectations.  People write an *essentially* non-vectorized
> function and expect Vectorize to produce a version of it which will
> out-perform explicit loops every time.  No magic bullets in this game.
>
> Bill.
>
>
>
> Bill Venables
> CSIRO Laboratories
> PO Box 120, Cleveland, 4163
> AUSTRALIA
> Office Phone (email preferred): +61 7 3826 7251
> Fax (if absolutely necessary):  +61 7 3826 7304
> Mobile: +61 4 8819 4402
> Home Phone: +61 7 3286 7700
> mailto:[EMAIL PROTECTED]
> http://www.cmis.csiro.au/bill.venables/
>
> -Original Message-
>
> From: Duncan Murdoch [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, 5 March 2008 9:36 AM
> To: Venables, Bill (CMIS, Cleveland)
> Cc: r-help@r-project.org
> Subject: Re: [R] vector manipulations
>
> On 3/4/2008 5:41 PM, [EMAIL PROTECTED] wrote:
> > Your problem is that your function log1( , ) is not vectorized with
> > respect to its arguments.  For a function to work in outer(...) it
> must
> > accept vectors for its first two arguments and it must produce a
> > parallel vector of responses.
> >
> > To quote the help information for outer:
> >
> > "FUN is called with these two extended vectors as arguments.
> Therefore,
> > it must be a vectorized function (or the name of one), expecting at
> > least two arguments."
> >
> > Sometimes Vectorize can be used to make a non-vectorized function into
> a
> > vectorized one, but the results are not always entirely satisfactory
> in
> > my experience.
>
> What problems have you seen?
>
> Duncan Murdoch
>
> __
> 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.


Re: [R] vector name

2007-09-17 Thread Stephen Tucker
Hi,

Either of the following should work (I assume there are 28 elements in your
list):

fdata <- cbind(as.matrix(as.data.frame(filtered)), myregime)

fdata <- cbind("colnames<-"(matrix(unlist(filtered),ncol=28),
 names(filtered)), myregime)

--- livia <[EMAIL PROTECTED]> wrote:

> 
> I have got a list named "filtered", I would like to construct alist named
> "fdata" as following:
> 
> fdata <- cbind(matrix(unlist(filtered),ncol=28), myregime)
> 
> If I try names(filtered), it gives all the correct name for each vector,
> but
> if I try names(fdata), it appears "filtered[[1]]"  "filtered[[2]]" ..., 
> 
> How can I keep the name in "fdata"? Could anyone give me some advice?
> -- 
> View this message in context:
> http://www.nabble.com/vector-name-tf4466025.html#a12733890
> 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.
> 



  

Luggage? GPS? Comic books?

__
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] vector name

2007-09-17 Thread Peter Dalgaard
livia wrote:
> I have got a list named "filtered", I would like to construct alist named
> "fdata" as following:
>
> fdata <- cbind(matrix(unlist(filtered),ncol=28), myregime)
>
> If I try names(filtered), it gives all the correct name for each vector, but
> if I try names(fdata), it appears "filtered[[1]]"  "filtered[[2]]" ..., 
>
> How can I keep the name in "fdata"? Could anyone give me some advice?
>   
You don't tell us quite enough about your data, but:

This would appear to giva a matrix, not a list? Did you perchance intend

do.call("cbind", c(filtered, list(myregime))

or maybe just

data.frame(filtered, myregime)

or

as.matrix(data.frame(filtered, myregime))

-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
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] vector fragment

2009-05-16 Thread Jorge Ivan Velez
Dear Jonas,
Try this:

> v<- c('stratosphere', 'mesosphere', 'troposphere')
> substr(v,3,4)
[1] "ra" "so" "op"

See ?substr for more information.

HTH,

Jorge


On Sat, May 16, 2009 at 9:52 AM, jonas garcia  wrote:

> Dear R users:
>
>
>
> I have got a simple question that has been bothering me for a while.
>
> Given a certain character vector, I would like to get in a separate vector
> a
> fragment of text, in this case the 3rd and 4th letters of each element.
>
>
>
> So, if:
>
>
>
> v<- c(“stratosphere”, “mesosphere”, “troposphere”)
>
>
>
> I want to obtain a different vector like this:
>
>
>
> c(“ra”, “so”, “op”)
>
>
>
> Thanks in advance for your help
>
>
>
> Jonas
>
>[[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.
>
>

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


Re: [R] vector size

2009-06-24 Thread Uwe Ligges



ogbos okike wrote:

Hi,
I have a data of size 981.1MB(1028707715) and I intend to calculate the
length of the data using tapply function in R. I was able to read the data
into R but when I tried to use the factor function, I had an error message
"Error: cannot allocate vector of size 2.0 Gb".
Can anybody tell me what to do? I have tried to increase the size of the
memory but I am not sure if R recognizes it as the error message persists.
Is there any other thing I need to do for R to recognize the memory
increase?



My guess is that this is a 32-bit version of R?
You need some 64-bit OS and 64-bit R or try to decrease the amount/size 
of objects that are in the same time in your memory.


Best,
Uwe Ligges



Thank you so much for any help.
Ogbos

[[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-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] vector sprintf argument

2007-11-29 Thread Moshe Olshansky
The only thing I can think of is:

> a <- c(1,2.7,5.19)
> F<-c("numeric:  %d ","%g ","%8.3f")
> x<-sapply(1:length(a),function(i)
sprintf(F[i],a[i]))
> y<-paste(x,sep="",collapse="")

But I am sure that you will get a better advice
elsewhere.

--- Tom Sgouros <[EMAIL PROTECTED]> wrote:

> 
> Hello all:
> 
> If I have a vector and a format, I want to do this:
> 
>  > A <- c(3,4,5)
>  > F <- "Number: %d, %d, %d"
>  > sprintf(F,A)
> 
> This doesn't work because A isn't three arguments,
> it's just one.  Is
> there a way to peel the vector members out of A so
> that sprintf can get
> at them?
> 
> I would like to do this because I have a large set
> of variable-length
> data that I'd like to print out in fancy formatted
> form.  The vectors
> range in length from 2 to 7.  Each row is different,
> so I had been
> hoping to do this with an array of formats, too.
> 
> I feel like I'm either overlooking something
> obvious, or have determined
> to do this in an un-R fashion.  Any advice is
> welcome.  (On this topic,
> that is.)
> 
> Many thanks,
> 
>  -tom
> 
> 
> -- 
>  
>  tomfool at as220 dot org
>  http://sgouros.com  
>  http://whatcheer.net
> 
> __
> 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] vector sprintf argument

2007-11-29 Thread Christos Hatzis
According to the help page sprintf will recycle its arguments:

The arguments (including fmt) are recycled if possible a whole number of
times to the length of the longest, and then the formatting is done in
parallel.  

Therefore the following works:

> sprintf("Number: %d", A)
[1] "Number: 3" "Number: 4" "Number: 5"

Another option is to create a character string from A and then print it:

> sprintf("Number: %s", paste(A, collapse=" "))
[1] "Number: 3 4 5"

-Christos

> -Original Message-
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On Behalf Of Moshe Olshansky
> Sent: Thursday, November 29, 2007 11:45 PM
> To: Tom Sgouros; r-help@r-project.org
> Subject: Re: [R] vector sprintf argument
> 
> The only thing I can think of is:
> 
> > a <- c(1,2.7,5.19)
> > F<-c("numeric:  %d ","%g ","%8.3f")
> > x<-sapply(1:length(a),function(i)
> sprintf(F[i],a[i]))
> > y<-paste(x,sep="",collapse="")
> 
> But I am sure that you will get a better advice elsewhere.
> 
> --- Tom Sgouros <[EMAIL PROTECTED]> wrote:
> 
> > 
> > Hello all:
> > 
> > If I have a vector and a format, I want to do this:
> > 
> >  > A <- c(3,4,5)
> >  > F <- "Number: %d, %d, %d"
> >  > sprintf(F,A)
> > 
> > This doesn't work because A isn't three arguments, it's 
> just one.  Is 
> > there a way to peel the vector members out of A so that sprintf can 
> > get at them?
> > 
> > I would like to do this because I have a large set of 
> variable-length 
> > data that I'd like to print out in fancy formatted form.  
> The vectors 
> > range in length from 2 to 7.  Each row is different, so I had been 
> > hoping to do this with an array of formats, too.
> > 
> > I feel like I'm either overlooking something obvious, or have 
> > determined to do this in an un-R fashion.  Any advice is 
> welcome.  (On 
> > this topic, that is.)
> > 
> > Many thanks,
> > 
> >  -tom
> > 
> > 
> > --
> >  
> >  tomfool at as220 dot org
> >  http://sgouros.com
> >  http://whatcheer.net
> > 
> > __
> > 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] vector in filename

2008-04-17 Thread Simon Blomberg
How about this:

x <- 1
y <- 1
mmax <- 10

my.files <- paste("foo", x:mmax, ".png", sep="")

for (i in my.files) {
png(filename=i, pointsize=20, width=600, height=600, units="px",
bg="#eaedd5")
plot(x, y)
dev.off()
x <- x+1
y <- y+1
}

Normally I would avoid for loops, but I think this application is a
legitimate use.

Cheers,

Simon.

On Fri, 2008-04-18 at 03:05 +0200, [Ricardo Rodriguez] Your XEN ICT Team
wrote:
> Hi,
> 
> I am trying to generate a group of graphics with an iteration. Some 
> thing like this...
> 
> x=1
> y=1
> max=10
> myfiles <- paste("foo", x:max, ".png", sep="")
> while (x =< max)
> {
> png(file=myfiles, pointsize = 20, width = 600, height = 600, 
> units = "px", bg="#eaedd5")
> plot(x,y)
> dev.off()   
> x=x+1
> y=y+1
> }
> 
> I am getting only one *.png file with the name of the first position in 
> myfiles and the content of the last graphic in the iteration. Please, 
> could you tell me if it is possible to iterate file= in any other way?
> 
> Thanks!
> 
> Ricardo
> 
> 
-- 
Simon Blomberg, BSc (Hons), PhD, MAppStat. 
Lecturer and Consultant Statistician 
Faculty of Biological and Chemical Sciences 
The University of Queensland 
St. Lucia Queensland 4072 
Australia
Room 320 Goddard Building (8)
T: +61 7 3365 2506
http://www.uq.edu.au/~uqsblomb
email: S.Blomberg1_at_uq.edu.au

Policies:
1.  I will NOT analyse your data for you.
2.  Your deadline is your problem.

The combination of some data and an aching desire for 
an answer does not ensure that a reasonable answer can 
be extracted from a given body of data. - John Tukey.

__
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] vector in filename

2008-04-18 Thread [Ricardo Rodriguez] Your XEN ICT Team
Hi,

Simon Blomberg wrote:
> How about this:
>
> x <- 1
> y <- 1
> mmax <- 10
>
> my.files <- paste("foo", x:mmax, ".png", sep="")
>
> for (i in my.files) {
>   png(filename=i, pointsize=20, width=600, height=600, units="px",
>   bg="#eaedd5")
>   plot(x, y)
>   dev.off()
>   x <- x+1
>   y <- y+1
> }
>   

It does the trick! Thanks.
> Normally I would avoid for loops, but I think this application is a
> legitimate use.

Please, why do you avoid looping normally? Thanks again.

Greetings,

Ricardo

-- 
Ricardo Rodríguez
Your XEN ICT Team

__
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] vector in filename

2008-04-18 Thread hadley wickham
On Thu, Apr 17, 2008 at 8:05 PM, [Ricardo Rodriguez] Your XEN ICT Team
<[EMAIL PROTECTED]> wrote:
> Hi,
>
>  I am trying to generate a group of graphics with an iteration. Some
>  thing like this...
>
>  x=1
>  y=1
>  max=10
>  myfiles <- paste("foo", x:max, ".png", sep="")
>  while (x =< max)
> {
> png(file=myfiles, pointsize = 20, width = 600, height = 600,
>  units = "px", bg="#eaedd5")
> plot(x,y)
> dev.off()
> x=x+1
> y=y+1
> }
>
>  I am getting only one *.png file with the name of the first position in
>  myfiles and the content of the last graphic in the iteration. Please,
>  could you tell me if it is possible to iterate file= in any other way?

Have you looked at ?png :

filename: the name of the output file. The page number is substituted
  if a C integer format is included in the character string, as
  in the default.  (The result must be less than 'PATH_MAX'
  characters long, and may be truncated if not. See
  'postscript' for further details.)  Tilde expansion is
  performed where supported by the platform.

so the default filename ("Rplot%03d.jpeg") already does what you want.

Hadley

-- 
http://had.co.nz/

__
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] vector in filename

2008-04-18 Thread [Ricardo Rodriguez] Your XEN ICT Team
Thanks Hadley,

hadley wickham wrote:
> Have you looked at ?png :
>
> filename: the name of the output file. The page number is substituted
>   if a C integer format is included in the character string, as
>   in the default.  (The result must be less than 'PATH_MAX'
>   characters long, and may be truncated if not. See
>   'postscript' for further details.)  Tilde expansion is
>   performed where supported by the platform.
>
> so the default filename ("Rplot%03d.jpeg") already does what you want.
>
> Hadley
>
>   

Yes, I've read this help page. But as far as I understand, this only 
allows to generated a "paged" file name, but not to include the value of 
a variable in the file name. Foo is a dummy name. It is only the 
numerical part of the name what variates in the samples above. I guess 
it won't be difficult to get Foo from values in a vector once I 
understand how the whole thing does work.

Cheers,

Ricardo


-- 
Ricardo Rodríguez
Your XEN ICT Team

__
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] vector in filename

2008-04-18 Thread [Ricardo Rodriguez] Your XEN ICT Team
Hi Richard, thanks for your input!

Richard Rowe wrote:
> which figures if you look at what you are doing line by line ... try it
>
>
> try something like:
>
> max=10
>
> for (i in 1:max){
> myfiles <- paste("foo", i, ".png", sep="") # generates names 
> foo1.png, foo2.png, etc
> png(file=myfiles, pointsize = 20, width = 600, height = 600, units = 
> "px", bg="#eaedd5")
>plot(x[i,],y[i,])# 
> you will need to change what you are plotting to something like 
> this
>dev.off()  }
>

There are at least two things I don't understand in your proposal:

1. How x and y variate? I mean, there is not x= or y= commands prior to 
enter for().
2. Whatever I set or not x and y, the code claims:

Error in x[i, ] : incorrect number of dimensions

Please, why to you use plot(x[i,],y[i,]) instead of plot(x,y)?

Thanks for your help,

Ricardo

-- 
Ricardo Rodríguez
Your XEN ICT Team

__
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] vector in filename

2008-04-18 Thread [Ricardo Rodriguez] Your XEN ICT Team
Mark,

Mark Leeds wrote:
> Oh, I'm sorry that didn't work. If you have time, can you resend it to me if
> you still have it ( I don't ) cause I'd like to see why. Thanks.

My fault! It does work! I've tried it this morning quickly, before 
leaving my SOHO, and it seems I was making any mistake. It does 
perfectly works as here...

x=1
y=1
max=10
myfiles <- paste("foo", x:max, ".png", sep="")
while (x =< max)
{
png(file=myfiles[x], pointsize = 20, width = 600, height = 600, 
units = "px", bg="#eaedd5")
plot(x,y)
dev.off()  
x=x+1
y=y+1
}

Thank you so much for your help and sorry for the noise!

Cheers,

Ricardo

-- 
Ricardo Rodríguez
Your XEN ICT Team

__
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] Vector Product question

2008-05-25 Thread Dimitris Rizopoulos

try this:

x <- c(3, 3, 1)
y <- c("x","h","y")

paste(rep(y, x), unlist(sapply(x, seq_len)), sep = "")


I hope it helps.

Best,
Dimitris


Dimitris Rizopoulos
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/(0)16/336899
Fax: +32/(0)16/337015
Web: http://med.kuleuven.be/biostat/
 http://www.student.kuleuven.be/~m0390867/dimitris.htm


Quoting Rory Winston <[EMAIL PROTECTED]>:


Hi

Ive looked around but I cant figure out how to do this without a for
loop. I have a vector of neural net weights from coef.nnet(), which
looks like c(3,3,1). I also have a list of weight prefixes, which are
c("x","h","y"). I would like to obtain a vector that looks like
c("x1","x2","x3","h1","h2","h3","y1") - i.e. if we think of the numeric
weight vector as a matrix B ([1 2 3],[1 2 3], [1 0 0]), its like a
paste() of the element in vector A[i] with each element in the row i:
B[i][j]. I can see that Ripley & Venables use the following, using
seq_len and paste() :

 wts <- object$wts
 wm <- c("b", paste("i", seq_len(object$n[1]), sep=""))
 if(object$n[2] > 0)
 wm <- c(wm, paste("h", seq_len(object$n[2]), sep=""))
 if(object$n[3] > 1)  wm <- c(wm,
 paste("o", seq_len(object$n[3]), sep=""))

Is it possible to compress this to a one-liner?

Cheers
Rory

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




Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm

__
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] Vector of Vectors

2009-04-01 Thread jim holtman
This may help in understanding how to access the list: notice that I
am using numeric indices and using the '[[' operator

> # generate a list with a varying number of values
> myList <- list()  # initialize
> for (i in 1:10) myList[[i]] <- seq(i)
> myList
[[1]]
[1] 1

[[2]]
[1] 1 2

[[3]]
[1] 1 2 3

[[4]]
[1] 1 2 3 4

[[5]]
[1] 1 2 3 4 5

[[6]]
[1] 1 2 3 4 5 6

[[7]]
[1] 1 2 3 4 5 6 7

[[8]]
[1] 1 2 3 4 5 6 7 8

[[9]]
[1] 1 2 3 4 5 6 7 8 9

[[10]]
 [1]  1  2  3  4  5  6  7  8  9 10

> myList[[4]]  # 1,2,3,4
[1] 1 2 3 4
> myList[[4]][2:3]  # 2, 3
[1] 2 3
>


On Wed, Apr 1, 2009 at 12:58 PM, Shawn Garbett
 wrote:
> I have a matrix of data. I need to scan the matrix and find every sequence
> from maxima to maxima across a row. I can write a loop to do this easily.
> Problem is, I can't figure out how to store the results. Each result is a
> vector of widely varying lengths. Ideally I'd like a vector of these, i.e. a
> vector of vectors, so I can quickly iterate through them and compute
> correlation coefficients.
>
> Here's a transcript of my fuddling to date:
>
>> x <- c(1,2,3)
>> y <- c(4,5)
>> v <- list("1"=x, "2"=y)
>> unlist(v["1"])
> 11 12 13
>  1  2  3
>> unlist(v["1"])[1]
> 11
>  1
>> unlist(v["1"])[2]
> 12
>  2
>> unlist(v["1"])[3]
> 13
>  3
>> unlist(v["2"])[3]
> 
>  NA
>> unlist(v["2"])[2]
> 22
>  5
>> v <- c(x,y)
>> v
> [1] 1 2 3 4 5
>> v <- vector()
>> v <- merge(v, x)
>> v
>     [,1] [,2]
> attr(,"row.names")
> integer(0)
>> v[1]
> [1] NA
>>
>
> As you can see, vectors aren't very cooperative and lists are downright
> baffling to me.
>
> Shawn Garbett 
> Vanderbilt Cancer Biology
> 220 Pierce Ave, PRB 715AA
> Nashville, TN 37232
> Office: 615.936.1975
> Cell: 615.397.8737
>
> __
> 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 that 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] Vector of matrix

2009-04-27 Thread Duncan Murdoch

On 4/27/2009 8:01 AM, Romildo Martins wrote:

Hello,

To specify a vector of matrices in R (which may have different sizes)?


M1 <- matrix(1,1,1)
M2 <- matrix(2,2,2)
vec <- list(M1, M2)



Thanks a lot!

Romildo

[[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-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] vector and NA

2009-06-23 Thread Chuck Cleland
On 6/23/2009 5:41 AM, Alfredo Alessandrini wrote:
> Hi,
> 
> I've a vector like this:
> 
> --
>> inc[,5]
>   [1]NANANANANANANA
>   [8]NANANANANANANA
>  [15]NANANANANANANA
>  [22]NANANANANANANA
>  [29]NANANANANANANA
>  [36]NANANANANANANA
>  [43]NANANANANANANA
>  [50]NANANANANANANA
>  [57]NANANANANANANA
>  [64]NANANANANANANA
>  [71]NANANANANANANA
>  [78]NANANANA 13.095503 10.140119  7.989186
>  [85]  8.711888  7.201234 13.029250 14.430755  8.662832  8.810785 14.421302
>  [92]  7.614985  7.548091  9.843389 14.977402 20.875255  7.787543  2.005056
>  [99]  4.016916  3.601773  4.140390  7.241999 13.280794 18.038902 18.762169
> [106]  4.280065  5.942021  6.292010 11.866446 19.450442 11.942362  6.224328
> [113]  3.176050  5.456117  2.733487  3.992823 13.633171 19.514301 25.085256
> [120]  5.640089  5.890486 12.421150 18.821420 22.478664 11.503805  7.051254
> [127]  7.560921 12.000394 20.464875 16.147598 13.746290  9.416060 35.848221
> [134] 36.739481 23.516759  7.317599  3.928247 10.371437 11.202935 12.574649
> [141]  6.906980  9.191260  7.080267  2.810271  5.494705 10.617141 14.578020
> [148] 10.981610  7.343975  2.179511  2.726651 10.794842  9.872493 19.842701
> [155] 10.525064 16.134541 29.283385 18.352996  9.216318  6.253805  2.704267
> [162]  4.274514  3.138237 12.296835 20.982433 13.001104  2.606328  3.333271
> [169]  5.514425  2.179244  5.381514  6.848380  3.794428  5.114591  4.975830
> [176]  3.809948 10.131608 14.145913
> ---
> 
> How can I extract a vector without the NA value?

na.omit(inc[,5])

?na.omit

> Regards,
> 
> Alfredo
> 
> __
> 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. 

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
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] vector and NA

2009-06-23 Thread Sandor Benczik



alfreale wrote:
> 
> 
> I've a vector like this:
> 
>> inc[,5]
> 
> How can I extract a vector without the NA value?
> 
> 

inc[,5][!is.na(inc[,5])]

-- 
View this message in context: 
http://www.nabble.com/vector-and-NA-tp24162879p24163839.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] vector and NA

2009-06-23 Thread John Kane


 ?is.na and its negative !is.na
Try something like this
xx  <- c(NA, NA, 1,  2,  3)
bb <- xx[!is.na(xx)]
bb

--- On Tue, 6/23/09, Alfredo Alessandrini  wrote:

> From: Alfredo Alessandrini 
> Subject: [R] vector and NA
> To: r-help@r-project.org
> Received: Tuesday, June 23, 2009, 5:41 AM
> Hi,
> 
> I've a vector like this:
> 
> --
> > inc[,5]
>   [1]        NA   
>     NA        NA   
>     NA        NA   
>     NA        NA
>   [8]        NA   
>     NA        NA   
>     NA        NA   
>     NA        NA
>  [15]        NA     
>   NA        NA     
>   NA        NA     
>   NA        NA
>  [22]        NA     
>   NA        NA     
>   NA        NA     
>   NA        NA
>  [29]        NA     
>   NA        NA     
>   NA        NA     
>   NA        NA
>  [36]        NA     
>   NA        NA     
>   NA        NA     
>   NA        NA
>  [43]        NA     
>   NA        NA     
>   NA        NA     
>   NA        NA
>  [50]        NA     
>   NA        NA     
>   NA        NA     
>   NA        NA
>  [57]        NA     
>   NA        NA     
>   NA        NA     
>   NA        NA
>  [64]        NA     
>   NA        NA     
>   NA        NA     
>   NA        NA
>  [71]        NA     
>   NA        NA     
>   NA        NA     
>   NA        NA
>  [78]        NA     
>   NA        NA     
>   NA 13.095503 10.140119  7.989186
>  [85]  8.711888  7.201234 13.029250
> 14.430755  8.662832  8.810785 14.421302
>  [92]  7.614985  7.548091  9.843389
> 14.977402 20.875255  7.787543  2.005056
>  [99]  4.016916  3.601773  4.140390 
> 7.241999 13.280794 18.038902 18.762169
> [106]  4.280065  5.942021  6.292010
> 11.866446 19.450442 11.942362  6.224328
> [113]  3.176050  5.456117  2.733487 
> 3.992823 13.633171 19.514301 25.085256
> [120]  5.640089  5.890486 12.421150 18.821420
> 22.478664 11.503805  7.051254
> [127]  7.560921 12.000394 20.464875 16.147598
> 13.746290  9.416060 35.848221
> [134] 36.739481 23.516759  7.317599  3.928247
> 10.371437 11.202935 12.574649
> [141]  6.906980  9.191260  7.080267 
> 2.810271  5.494705 10.617141 14.578020
> [148] 10.981610  7.343975  2.179511 
> 2.726651 10.794842  9.872493 19.842701
> [155] 10.525064 16.134541 29.283385 18.352996 
> 9.216318  6.253805  2.704267
> [162]  4.274514  3.138237 12.296835 20.982433
> 13.001104  2.606328  3.333271
> [169]  5.514425  2.179244  5.381514 
> 6.848380  3.794428  5.114591  4.975830
> [176]  3.809948 10.131608 14.145913
> >
> ---
> 
> How can I extract a vector without the NA value?
> 
> 
> Regards,
> 
> Alfredo
> 
> __
> 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 new Internet Explorer® 8 - Faster, safer, easier.  Optimiz
etexplorer/

__
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] Vector of string

2009-06-23 Thread Henrique Dallazuanna
Try this:

s <- c("12384", "TYU123123","AVC3939", "hhr1919", "TYU0029")
grep("^TYU", s)

On Tue, Jun 23, 2009 at 11:51 AM, njhuang86  wrote:

>
> Hi all. Suppose I have a vector of strings ie: ["12384", "TYU123123",
> "AVC3939", "hhr1919", "TYU0029"]
>
> Is there an efficient method that would allow me to return a vector of the
> position of strings that start with "TYU"? So essentially, I would like to
> get back in return [2, 5]. Anyways, any help with be greatly appreciated!
> --
> View this message in context:
> http://www.nabble.com/Vector-of-string-tp24167271p24167271.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.
>



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


Re: [R] Vector of string

2009-06-23 Thread Sandor Benczik



njhuang86 wrote:
> 
> Hi all. Suppose I have a vector of strings ie: ["12384", "AVC_TYU123123", 
> "ESPN_TYU", "TYU_TYU", "AVC3939", "hhr1919", "TYU0029"]
> 
> Is there an efficient method that would allow me to return a vector of the
> position of strings that start with "TYU"? So essentially, I would like to
> get back in return [4, 7]. Anyways, any help with be greatly appreciated!
> 

?grep

The pattern  is  "^TYU" with perl=T, if I am not mistaken.

-- 
View this message in context: 
http://www.nabble.com/Vector-of-string-tp24167271p24167332.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] vector size: Fixed

2009-08-25 Thread ogbos okike
Hi Uwe,
I am pleased to inform you that this problem has, following your hint, been
resolved.  I installed 64-bit version of R and I was alright.
Thanks again for your time.
Ogbos

2009/6/24 Uwe Ligges 

>
>
> ogbos okike wrote:
>
>> Hi,
>> I have a data of size 981.1MB(1028707715) and I intend to calculate the
>> length of the data using tapply function in R. I was able to read the data
>> into R but when I tried to use the factor function, I had an error message
>> "Error: cannot allocate vector of size 2.0 Gb".
>> Can anybody tell me what to do? I have tried to increase the size of the
>> memory but I am not sure if R recognizes it as the error message persists.
>> Is there any other thing I need to do for R to recognize the memory
>> increase?
>>
>
>
> My guess is that this is a 32-bit version of R?
> You need some 64-bit OS and 64-bit R or try to decrease the amount/size of
> objects that are in the same time in your memory.
>
> Best,
> Uwe Ligges
>
>
>  Thank you so much for any help.
>> Ogbos
>>
>>[[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.
>>
>

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


Re: [R] vector of Vectors

2009-09-08 Thread Schalk Heunis
You want to use list:
a = list()
a[[1]] = c(1,2,3)
a[[2]] = c(1,2,3)

Note the [[..]] operator - check the "An Introduction to R" manual for
more details

Schalk Heunis



On Wed, Sep 9, 2009 at 6:00 AM,  wrote:
> I just learned that vectors can't contain vectors, which frankly simply 
> confuses me (can you imagine arrays or lists in any other language not being 
> able to contain arrays or lists?). At any rate, I need to create a data 
> structure (size to be determined at runtime) which I will instantiate and 
> then fill with vectors using a for loop. Clearly I'm new to the R game. Data 
> Frame doesnt seem to be the right tool clearly.
>
> __
> 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] vector of Vectors

2009-09-09 Thread Giovanni Petris

The code below seems to contradict your claim that vectors cannot
contain vectors.

> zz <- vector(mode = "list", length = 3)
> zz
[[1]]
NULL

[[2]]
NULL

[[3]]
NULL

Best,
Giovanni

> Date: Tue, 08 Sep 2009 23:00:54 -0500 (CDT)
> From: sclar...@illinois.edu
> Sender: r-help-boun...@r-project.org
> Precedence: list
> 
> I just learned that vectors can't contain vectors, which frankly simply 
> confuses me (can you imagine arrays or lists in any other language not being 
> able to contain arrays or lists?). At any rate, I need to create a data 
> structure (size to be determined at runtime) which I will instantiate and 
> then fill with vectors using a for loop. Clearly I'm new to the R game. Data 
> Frame doesnt seem to be the right tool clearly.
> 
> __
> 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.
> 
> 

-- 

Giovanni Petris  
Associate Professor
Department of Mathematical Sciences
University of Arkansas - Fayetteville, AR 72701
Ph: (479) 575-6324, 575-8630 (fax)
http://definetti.uark.edu/~gpetris/

__
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] vector operation using regexpr?

2008-08-20 Thread markleeds
Hi: I think you want regexpr so below does what you want but it doesn't 
handle the case when L isn't in the second column. I'm still trying to 
figure that out but don't count on it. Hopefully someone else will reply 
with that piece.


DF <- data.frame(col1="L",col2="MAIL",col3="PLOY")
print(DF)
index <- regexpr(DF$col1,DF$col2)
result <- substr(DF$col3,index,index)



On Wed, Aug 20, 2008 at  3:26 PM, John Christie wrote:


Hi,

Here's my problem... I have a data frame with three columns containing 
strings.  The first columns is a simple character. I want to get the 
index of that character in the second column and use it to extract the 
item from the third column.  I can do this using a scalar method.  But 
I'm not finding a vector method.  An example is below.


col1  col2  col3
'L' 'MAIL '   'PLOY'

What I want to do with the above is find the index of col1 in col2 (4) 
and then use it to extract the character from col3 ('Y').  I could do 
the last part if I could get the index in a vector fashion.


So, the shorter question is, how do I get the index of the letter in 
col1 as it is found in col2?


__
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] vector operation using regexpr?

2008-08-20 Thread Charles C. Berry

On Wed, 20 Aug 2008, John Christie wrote:


Hi,

Here's my problem... I have a data frame with three columns containing 
strings.  The first columns is a simple character. I want to get the index of 
that character in the second column and use it to extract the item from the 
third column.  I can do this using a scalar method.  But I'm not finding a 
vector method.  An example is below.


col1  col2  col3
'L' 'MAIL '   'PLOY'

What I want to do with the above is find the index of col1 in col2 (4) and 
then use it to extract the character from col3 ('Y').  I could do the last 
part if I could get the index in a vector fashion.


So, the shorter question is, how do I get the index of the letter in col1 as 
it is found in col2?



Let me count the ways... On second thought, let someone else count the 
ways. But here is one


## suppose 'df' is your data.frame
a.list <- lapply( df, function(x) strsplit(as.character(x), "") )
with(a.list, mapply( function(x,y,z) z[x==y], col1, col2, col3 ) )


This will return all matches in each row. You can use 'match(x,y,0)' in 
place of 'x==y' to get just the first one.



And if you KNOW a match in each row exists and is unique, this will work:

with(a.list, do.call(rbind,col3)[ do.call(rbind,col2) == col1 ] )

but I would not trust it.

HTH,

Chuck



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



Charles C. Berry(858) 534-2098
Dept of Family/Preventive Medicine
E mailto:[EMAIL PROTECTED]  UC San Diego
http://famprevmed.ucsd.edu/faculty/cberry/  La Jolla, San Diego 92093-0901

__
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] vector operation using regexpr?

2008-08-20 Thread markleeds
Hi  John: I didn't realize that that was your problem. You can make it 
work for any number of rows by putting it in lapply as below.
I'm sorry for the misunderstanding. I'll send to the list also since I 
guess my last solution was kind of bad now that I understand what you 
want.


DF <- 
data.frame(col1=c("L","T"),col2=c("MAIL","KITE"),col3=c("PLOY","SIX"))

print(DF)

newcol <- lapply(1:nrow(DF), function(.row) {
  result <- NULL
  if ( regexpr(DF[.row,1],DF[.row,2]) != -1 ) result <- 
substr(DF[.row,3],regexpr(DF[.row,1],DF[.row,2]),regexpr(DF[.row,1],DF[.row,2]))

  result
})

print(newcol)

# BELOW IS FOR IF YOU ONLY WANT TO KEEP THE ONES THAT WERE FOUND
# AND NOT THE NULLS
newcol <- newcol[!sapply(newcol,is.null)]
print(newcol)





On Thu, Aug 21, 2008 at 12:25 AM, John Christie wrote:

The problem with the grep family of commands is that they either test 
a string against a list of strings or test a list of strings against a 
string.  But they cannot do both simultaneously.  Your example only 
works if there is only one row.


On Aug 21, 2008, at 12:30 AM, [EMAIL PROTECTED] wrote:

John: Below takes care of when L is not there but it's too ugly so 
I'm not even going to send this to the list. There should be a 
better way of doing it but I'm still learning ( I guess one can 
consider me a senior newbie !!! ) also so I don't know it. Good luck.


DF <- data.frame(col1="Y",col2="MAIL",col3="PLOY")
result <- NULL
if ( regexpr(DF$col1,DF$col2) != -1 ) result <- substr(DF 
$col3,regexpr(DF$col1,DF$col2),regexpr(DF$col1,DF$col2))

print(result)



On Wed, Aug 20, 2008 at 11:21 PM, [EMAIL PROTECTED] wrote:

Hi: I think you want regexpr so below does what you want but it 
doesn't handle the case when L isn't in the second column. I'm 
still trying to figure that out but don't count on it. Hopefully 
someone else will reply with that piece.


DF <- data.frame(col1="L",col2="MAIL",col3="PLOY")
print(DF)
index <- regexpr(DF$col1,DF$col2)
result <- substr(DF$col3,index,index)



On Wed, Aug 20, 2008 at  3:26 PM, John Christie wrote:


Hi,

Here's my problem... I have a data frame with three columns 
containing strings.  The first columns is a simple character. I 
want to get the index of that character in the second column and 
use it to extract the item from the third column.  I can do this 
using a scalar method.  But I'm not finding a vector method.  An 
example is below.


col1  col2  col3
'L' 'MAIL '   'PLOY'

What I want to do with the above is find the index of col1 in col2 
(4) and then use it to extract the character from col3 ('Y').  I 
could do the last part if I could get the index in a vector 
fashion.


So, the shorter question is, how do I get the index of the letter 
in col1 as it is found in col2?


__
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] Vector Size Error Message

2007-09-11 Thread jim holtman
What operating system are you running on?  Do you know if you have run
out of physical memory?  If on Windows, what do you have
'--max-mem-size' set to on the command line invoking the RGUI?

On 9/11/07, Sasse, Mark <[EMAIL PROTECTED]> wrote:
> I have been using R off an on for approximately 3 months.  As such, I am
> not very knowledgeable about coding in R.  Currently I am running into
> the following problem.  I'm using scan to make data available in R.  The
> data I'm loading consists of over 400,000 records with 5 data fields.
> After running the following statement:
>
>
>
> mod1<-glm(DefMigFlag~MaxFICO, family=binomial(link="logit"))
>
>
>
> R returns the following error message:
>
>
>
> Error: cannot allocate vector of size 3.3 Mb
>
>
>
> Can anyone tell me how what I need to do to enable R to execute my glm
> statement?
>
>
>
> Thanks very much!
>
>
>
> Mark Sasse
>
>
>
> [EMAIL PROTECTED]
>
>
>
>
>
>
> -
> Use of email is inherently insecure. Confidential information,
> including account information, and personally identifiable
> information, should not be transmitted via email, or email
> attachment.  In no event shall Citizens or any of its affiliates
> accept any responsibility for the loss, use or misuse of any
> information including confidential information, which is sent to
> Citizens or its affiliates via email, or email attachment. Citizens
> does not guarantee the accuracy of any email or email attachment,
> that an email will be received by Citizens or that Citizens will
> respond to any email.
>
> This email message is confidential and/or privileged. It is to be
> used by the intended recipient only.  Use of the information
> contained in this email by anyone other than the intended recipient
> is strictly prohibited. If you have received this message in error,
> please notify the sender immediately and promptly destroy any
> record of this email.
>
>[[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.
>


-- 
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] vector sprintf argument [SEC=UNCLASSIFIED]

2007-11-29 Thread Crombie, Joe
Hi Tom,

Try this:

> G <- "Number: %s"
> sprintf(G, toString(A))
[1] "Number: 3, 4, 5"

Cheers  Joe

 
Joe Crombie
 
Biosecurity and Information Sciences
Bureau of Rural Science
Canberra  Australia
 
p: +61 2 6272 5906
e: [EMAIL PROTECTED]
 

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
On Behalf Of Tom Sgouros
Sent: Friday, 30 November 2007 12:43 PM
To: r-help@r-project.org
Subject: [R] vector sprintf argument


Hello all:

If I have a vector and a format, I want to do this:

 > A <- c(3,4,5)
 > F <- "Number: %d, %d, %d"
 > sprintf(F,A)

This doesn't work because A isn't three arguments, it's just one.  Is
there a way to peel the vector members out of A so that sprintf can get
at them?

I would like to do this because I have a large set of variable-length
data that I'd like to print out in fancy formatted form.  The vectors
range in length from 2 to 7.  Each row is different, so I had been
hoping to do this with an array of formats, too.

I feel like I'm either overlooking something obvious, or have determined
to do this in an un-R fashion.  Any advice is welcome.  (On this topic,
that is.)

Many thanks,

 -tom


--
 
 tomfool at as220 dot org
 http://sgouros.com
 http://whatcheer.net

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

--IMPORTANT - This message has been issued by The Department of 
Agriculture, Fisheries and Forestry (DAFF). The information transmitted is for 
the use of the intended recipient only and may contain confidential and/or 
legally privileged material. It is your responsibility to check any attachments 
for viruses and defects before opening or sending them on. 

Any reproduction, publication, communication, re-transmission, disclosure, 
dissemination or other use of the information contained in this e-mail by 
persons or entities other than the intended recipient is prohibited. The taking 
of any action in reliance upon this information by persons or entities other 
than the intended recipient is prohibited. If you have received this e-mail in 
error please notify the sender and delete all copies of this transmission 
together with any attachments. If you have received this e-mail as part of a 
valid mailing list and no longer want to receive a message such as this one 
advise the sender by return e-mail accordingly. Only e-mail correspondence 
which includes this footer, has been authorised by DAFF 
--

__
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] Vector Autocorrelation Function in R?

2009-01-23 Thread Stefan Grosse
Andreas Klein schrieb:
> Hello.
>
>
> Does anyone know, if there is a function in R to compute the vector 
> autocorrelations?
>
>   
?ccf on bivariate time series.

+ have a look at the vars package though I am not sure what exactly you
are trying.

hth
Stefan

__
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] Vector of ones and zeros

2008-11-19 Thread Rolf Turner


On 20/11/2008, at 11:47 AM, [EMAIL PROTECTED] wrote:


Dear R people,
what functions generate respectively vectors with each element is  
respectively zero and one.

sorry for my credulous questions and many thanks in advance.


If you want a *random* (i.i.d.) vector of zeroes and ones, then the  
following sort of thing

will do it:

sample(0:1,42,TRUE) # TRUE is necessary for sampling with replacement.
	sample(0:1,42,TRUE,prob=c(0.25,0.75)) # 1/4 zeroes and 3/4 ones on  
average; the default is equal probabilities.


If you want some non-random structure, or if you want serial  
dependence between the entries

you need to make your question more explicit.

*Do* read the posting guide!

cheers,

Rolf Turner

##
Attention:\ This e-mail message is privileged and confid...{{dropped:9}}

__
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] vector of zeros and ones

2008-11-19 Thread Erik Iverson

a <- rep(1, 1) , see ?rep

[EMAIL PROTECTED] wrote:

Dear Rolf, thank you for reply,
I am interested with non random numbers. To be more precise, I would like to 
obtain two vectors a and b with a=(1,1,1,..,1,1) and b=(0,0,,0,0). 
The length of a and b is 1.
Thank you



Écoutez gratuitement le nouveau single de Noir Désir et découvrez d'autres 
titres en affinité avec vos goûts musicaux ! 
http://musiline.voila.fr/player/generate/4/15/31774/?intitule=Gagnants+%2F+Perdants

[[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-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] Vector of ones and zeros

2008-11-20 Thread Yihui Xie
or rbinom(n, size = 1, prob)

Regards,
Yihui
--
Yihui Xie <[EMAIL PROTECTED]>
Phone: +86-(0)10-82509086 Fax: +86-(0)10-82509086
Mobile: +86-15810805877
Homepage: http://www.yihui.name
School of Statistics, Room 1037, Mingde Main Building,
Renmin University of China, Beijing, 100872, China



On Thu, Nov 20, 2008 at 6:57 AM, Rolf Turner <[EMAIL PROTECTED]> wrote:
>
> On 20/11/2008, at 11:47 AM, [EMAIL PROTECTED] wrote:
>
>> Dear R people,
>> what functions generate respectively vectors with each element is
>> respectively zero and one.
>> sorry for my credulous questions and many thanks in advance.
>
> If you want a *random* (i.i.d.) vector of zeroes and ones, then the
> following sort of thing
> will do it:
>
>sample(0:1,42,TRUE) # TRUE is necessary for sampling with
> replacement.
>sample(0:1,42,TRUE,prob=c(0.25,0.75)) # 1/4 zeroes and 3/4 ones on
> average; the default is equal probabilities.
>
> If you want some non-random structure, or if you want serial dependence
> between the entries
> you need to make your question more explicit.
>
> *Do* read the posting guide!
>
>cheers,
>
>Rolf Turner
>
> ##
> Attention:\ This e-mail message is privileged and confid...{{dropped:9}}
>
> __
> 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] Vector lty argrument for lines or plot

2008-11-20 Thread baptiste auguie

Hi,

If you wish to connect each point to the next with a different  
linetype, I think your best bet is to use segments()



x <- stats::runif(12); y <- stats::rnorm(12)
i <- order(x,y); x <- x[i]; y <- y[i]
plot(x, y)
s <- seq(length(x)-1)
segments(x[s], y[s], x[s+1], y[s+1], lty=1:10)


If, however, you wish to plot several groups of lines with different  
linetypes, then matlines() should do the job. Both of these make  
actual use of lty as a vector, while polygon(), abline(), plot(),  
lines() will only use the first value (as far as i can see).



Hope this helps,

baptiste

On 20 Nov 2008, at 20:24, Brian Diggs wrote:

I am confused by the behavior of the lines function when the lty  
argument is a vector.  ?lines indicates that lty is a valid  
parameter, but says nothing else about it.  ?plot.xy (which I think  
is what gets called) refers back to ?lines.  ?plot.default says to  
see ?par.  In ?par, about lty it says "Some functions such as lines  
accept a vector of values which are recycled. Other uses will take  
just the first value if a vector of length greater than one is  
supplied."  However, I cannot get lines to use more than one type of  
line.  Some example code:


pt <- runif(10)
plot(pt)
lines(pt, type="c", lty=1:10)

I expected each subsequent line segment to be in a different style.   
Only the first seems to be used.  The same is true for plot:


plot(pt, type="b", lty=1:10)

uses only one style of line segment (although no documentation says  
explicitly that the others would be used).  It doesn't matter the  
order or manner of specification, only the first is used.


plot(pt)
lines(pt, type="c", lty=c("dashed","solid"))

plot(pt)
lines(pt, type="c", lty=c("FF", "11"))

I have used a vector of lty before (in legend) and it cycled through  
all the values.  Am I misunderstanding what a vector lty to lines  
means, or is this a bug?


I'm running on Windows XP Pro, if that might matter.


sessionInfo()

R version 2.8.0 (2008-10-20)
i386-pc-mingw32

locale:
LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States. 
1252;LC_MONETARY=English_United States. 
1252;LC_NUMERIC=C;LC_TIME=English_United States.1252


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

--
Brian Diggs, Ph.D.
Senior Research Associate, Department of Surgery, Oregon Health &  
Science University




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


_

Baptiste Auguié

School of Physics
University of Exeter
Stocker Road,
Exeter, Devon,
EX4 4QL, UK

Phone: +44 1392 264187

http://newton.ex.ac.uk/research/emag

__
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] Vector lty argrument for lines or plot

2008-11-21 Thread Brian Diggs
Thank you for the suggestion, baptiste.  segments() does do exactly what I was 
wanting and matplot()/matlines() is probably a better solution to what I was 
trying to do.

However, I am still concerned about the discrepancy between the documentation 
in ?par and the behavior of lines().  Should lines() be changed to cycle over a 
vector of lty (so that it agrees with the documentation in ?par)?  Should the 
documentation of par be changed to use a different example of a function that 
cycles over a vector of lty (segments() being a good candidate)?  Or are both 
lines() and ?par correct and there is a situation which lines() does cycle over 
a vector of lty that I (and at least baptiste as well) do not understand?  The 
middle option is certainly the easiest, and I think the correct one, but I 
wanted to rule out the last one before filing a bug report.

-- 
Brian Diggs, Ph.D.
Senior Research Associate, Department of Surgery, 
Oregon Health & Science University

baptiste auguie wrote:
> Hi,
> 
> If you wish to connect each point to the next with a different linetype, 
> I think your best bet is to use segments()
> 
> 
> x <- stats::runif(12); y <- stats::rnorm(12)
> i <- order(x,y); x <- x[i]; y <- y[i]
> plot(x, y)
> s <- seq(length(x)-1)
> segments(x[s], y[s], x[s+1], y[s+1], lty=1:10)
> 
> 
> If, however, you wish to plot several groups of lines with different 
> linetypes, then matlines() should do the job. Both of these make actual 
> use of lty as a vector, while polygon(), abline(), plot(), lines() will 
> only use the first value (as far as i can see).
> 
> 
> Hope this helps,
> 
> baptiste
> 
> On 20 Nov 2008, at 20:24, Brian Diggs wrote:
> 
>> I am confused by the behavior of the lines function when the lty 
>> argument is a vector.  ?lines indicates that lty is a valid parameter, 
>> but says nothing else about it.  ?plot.xy (which I think is what gets 
>> called) refers back to ?lines.  ?plot.default says to see ?par.  In 
>> ?par, about lty it says "Some functions such as lines accept a vector 
>> of values which are recycled. Other uses will take just the first 
>> value if a vector of length greater than one is supplied."  However, I 
>> cannot get lines to use more than one type of line.  Some example code:
>>
>> pt <- runif(10)
>> plot(pt)
>> lines(pt, type="c", lty=1:10)
>>
>> I expected each subsequent line segment to be in a different style.  
>> Only the first seems to be used.  The same is true for plot:
>>
>> plot(pt, type="b", lty=1:10)
>>
>> uses only one style of line segment (although no documentation says 
>> explicitly that the others would be used).  It doesn't matter the 
>> order or manner of specification, only the first is used.
>>
>> plot(pt)
>> lines(pt, type="c", lty=c("dashed","solid"))
>>
>> plot(pt)
>> lines(pt, type="c", lty=c("FF", "11"))
>>
>> I have used a vector of lty before (in legend) and it cycled through 
>> all the values.  Am I misunderstanding what a vector lty to lines 
>> means, or is this a bug?
>>
>> I'm running on Windows XP Pro, if that might matter.
>>
>>> sessionInfo()
>> R version 2.8.0 (2008-10-20)
>> i386-pc-mingw32
>>
>> locale:
>> LC_COLLATE=English_United States.1252;LC_CTYPE=English_United 
>> States.1252;LC_MONETARY=English_United 
>> States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252
>>
>> attached base packages:
>> [1] stats graphics  grDevices utils datasets  methods   base
>>
>> -- 
>> Brian Diggs, Ph.D.
>> Senior Research Associate, Department of Surgery, Oregon Health & 
>> Science University
>>
>>
>>
>> __
>> 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.
> 
> _
> 
> Baptiste Auguié
> 
> School of Physics
> University of Exeter
> Stocker Road,
> Exeter, Devon,
> EX4 4QL, UK
> 
> Phone: +44 1392 264187
> 
> http://newton.ex.ac.uk/research/emag
> 
> __
> 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] Vector lty argrument for lines or plot

2008-11-21 Thread Peter Dalgaard
Brian Diggs wrote:
>Thank you for the suggestion, baptiste. segments() does do exactly what
I was wanting and matplot()/matlines() is probably a better solution to
what I was trying to do.
> 
> However, I am still concerned about the discrepancy between the
documentation in ?par and the behavior of lines(). Should lines() be
changed to cycle over a vector of lty (so that it agrees with the
documentation in ?par)? Should the documentation of par be changed to
use a different example of a function that cycles over a vector of lty
(segments() being a good candidate)? Or are both lines() and ?par
correct and there is a situation which lines() does cycle over a vector
of lty that I (and at least baptiste as well) do not understand? The
middle option is certainly the easiest, and I think the correct one, but
I wanted to rule out the last one before filing a bug report.
> 

The documentation for lines has

 'lwd' can be a vector: its first element will apply to lines but
 the whole vector to symbols (recycled as necessary).

which really is true, and you might expect something similar for lty,
but lty does not apply to symbols.  So the text in ?par is most likely a
copy-paste blunder. In any case, this usage is somewhat far-fetched and
a reference matplot() or segments() would, in both cases, express more
clearly what ?par is trying to say.



-- 
   O__   Peter Dalgaard Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
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] vector graphics/ ungroup and edit in CorelDraw

2007-10-19 Thread Prof Brian Ripley
The R graphics model is low-level, and the problem is CorelDraw's limited 
capabilities (Adobe Illustrator seems to do rather better with postscript 
generated by R).  The XFig and SVG drivers may produce output that is more 
easily editable, but ultimately the problem is that R graphics is done by 
precise placement of basic elements (lines, rectangles, polygons, text) 
and not designed to be post-processed.

One of my students had some success generating SVG plots via RSvgDevice 
and editing with Inkscape: that has announced PDF import support, but I've 
not yet tried it.


On Thu, 18 Oct 2007, Sam McClatchie wrote:

> System:
> Linux kernel 2.6.15 Ubuntu dapper
> R version 2.5.1
> ESS 5.2.11 on Emacs 21.4.1
> -
> Colleagues
>
> Having read the posts on producing perfect graphs in R, or using
> inkscape to edit R graphics output, I have a related question.
>
> Lately I am publishing in a journal that is very picky about their
> graphics formats. It is more efficient for me to get the final picky
> details of each graph done by our graphics department, who use Windows
> CorelDraw. The problem is that I have not yet been able to give them a
> vector graphics format that can be ungrouped in CorelDraw for editing.
> Bitmaps cannot be ungrouped . The
> standard postscript that I am producing in R cannot be ungrouped either,
> and comes into CorelDraw looking fragmented. While I may be doing
> something odd in the production of my postscript files, they look fine
> elsewhere, and print well, so I don't think there is a problem.
>
> Can anyone tell me how to produce vector graphics in R that can be
> ungrouped for editing in CorelDraw?
>
> Best fishes
>
> Sam
>
>

-- 
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] vector graphics/ ungroup and edit in CorelDraw

2007-10-18 Thread Dieter Menne
Sam McClatchie  noaa.gov> writes:

> Can anyone tell me how to produce vector graphics in R that can be 
> ungrouped for editing in CorelDraw?

Postscript should do. In theory, EMF will do too, but it quirky (at least with
my version of CorelDraw).


Dieter

__
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] vector replacement 1/0 to P/A

2009-08-18 Thread Chuck Cleland
On 8/17/2009 10:22 AM, Lana Schaffer wrote:
> Hi,
> Can someone suggest an efficient way to substitute a vector/matrix
> which contains 1's and 0's to P's and A's (resp.)?
> Thanks,
> Lana

  Here is one approach:

mymat <- matrix(rbinom(15, 1, .5), ncol=3)

mymat
 [,1] [,2] [,3]
[1,]100
[2,]001
[3,]101
[4,]010
[5,]110

mymat[] <- sapply(mymat, function(x){ifelse(x == 1, 'P', ifelse(x == 0,
'A', NA))})

mymat
 [,1] [,2] [,3]
[1,] "P"  "A"  "A"
[2,] "A"  "A"  "P"
[3,] "P"  "A"  "P"
[4,] "A"  "P"  "A"
[5,] "P"  "P"  "A"

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

-- 
Chuck Cleland, Ph.D.
NDRI, Inc. (www.ndri.org)
71 West 23rd Street, 8th floor
New York, NY 10010
tel: (212) 845-4495 (Tu, Th)
tel: (732) 512-0171 (M, W, F)
fax: (917) 438-0894

__
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] vector replacement 1/0 to P/A

2009-08-18 Thread Duncan Murdoch

On 17/08/2009 10:22 AM, Lana Schaffer wrote:

Hi,
Can someone suggest an efficient way to substitute a vector/matrix
which contains 1's and 0's to P's and A's (resp.)?


x[x == 1] <- "P"
x[x == "0"] <- "A"

(I added the quotes around 0 on the second line because the first line 
changed x to a character vector.  This isn't necessary, "0" == 0 comes 
out TRUE, but I think it is clearer.)


Duncan Murdoch

__
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] vector replacement 1/0 to P/A

2009-08-18 Thread jim holtman
Will this do it:

> x <- sample(0:1,10,TRUE)
> x
 [1] 1 0 0 1 0 1 0 0 0 0
> ifelse(x == 1, "P", "A")
 [1] "P" "A" "A" "P" "A" "P" "A" "A" "A" "A"
>


On Mon, Aug 17, 2009 at 10:22 AM, Lana Schaffer wrote:
> Hi,
> Can someone suggest an efficient way to substitute a vector/matrix
> which contains 1's and 0's to P's and A's (resp.)?
> Thanks,
> Lana
> __
> 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 that 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] vector replacement 1/0 to P/A

2009-08-18 Thread Petr PIKAL
Hi

As matrix is vector with dim attribute

 mymat<-ifelse(mymat==0, "A","P")

should be sufficient. 

Even with data frame it works

mydf<-data.frame(mymat)
mydf<-ifelse(mydf==0, "A","P")
 mydf
 X1  X2  X3 
[1,] "P" "P" "A"
[2,] "A" "A" "A"
[3,] "A" "A" "P"
[4,] "A" "A" "P"
[5,] "P" "P" "P"

Regards
Petr


r-help-boun...@r-project.org napsal dne 18.08.2009 13:58:51:

> On 8/17/2009 10:22 AM, Lana Schaffer wrote:
> > Hi,
> > Can someone suggest an efficient way to substitute a vector/matrix
> > which contains 1's and 0's to P's and A's (resp.)?
> > Thanks,
> > Lana
> 
>   Here is one approach:
> 
> mymat <- matrix(rbinom(15, 1, .5), ncol=3)
> 
> mymat
>  [,1] [,2] [,3]
> [1,]100
> [2,]001
> [3,]101
> [4,]010
> [5,]110
> 
> mymat[] <- sapply(mymat, function(x){ifelse(x == 1, 'P', ifelse(x == 0,
> 'A', NA))})
> 
> mymat
>  [,1] [,2] [,3]
> [1,] "P"  "A"  "A"
> [2,] "A"  "A"  "P"
> [3,] "P"  "A"  "P"
> [4,] "A"  "P"  "A"
> [5,] "P"  "P"  "A"
> 
> > __
> > 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. 
> 
> -- 
> Chuck Cleland, Ph.D.
> NDRI, Inc. (www.ndri.org)
> 71 West 23rd Street, 8th floor
> New York, NY 10010
> tel: (212) 845-4495 (Tu, Th)
> tel: (732) 512-0171 (M, W, F)
> fax: (917) 438-0894
> 
> __
> 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.