[R] subset function unexpected behavior

2010-02-02 Thread David Katz

I was surprised to see this unexpected behavior of subset in a for loop. I
looked in subset.data.frame and it seemed to me that both versions should
work, since the subset call should be evaluated in the global environment -
but perhaps I don't understand environments well enough. Can someone
enlighten me? In any case, this is a bit of a gotcha for naive users of
subset.

input.data -
  data.frame(sch=c(1,1,2,2),
 pop=c(100,200,300,400))

school.var - sch

school.list - 1:2

for(sch in school.list){
  print(sch)
  #do this before subset!:
  right.sch.p -
input.data[,school.var] == sch
  print(  subset(input.data,right.sch.p)) #this is what I expected
}

## [1] 1
##   sch pop
## 1   1 100
## 2   1 200
## [1] 2
##   sch pop
## 3   2 300
## 4   2 400


for(sch in school.list){
  print(sch)
  print(subset(input.data,input.data[,school.var] == sch)) #note - compact
version fails!
}

## [1] 1
##   sch pop
## 1   1 100
## 2   1 200
## 3   2 300
## 4   2 400
## [1] 2
##   sch pop
## 1   1 100
## 2   1 200
## 3   2 300
## 4   2 400

-- 
View this message in context: 
http://n4.nabble.com/subset-function-unexpected-behavior-tp1459535p1459535.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] Odp: How to repeat for function?

2010-02-02 Thread Petr PIKAL
Hi

r-help-boun...@r-project.org napsal dne 01.02.2010 18:14:04:

 
 Dear Petr,
 
 The intention is to get a ratio value for every observations (1400 obs) 
for 
 every variable (4 variables). 

Well, maybe that

mat-matrix(runif(12),4,3)
ratiomat-t(t(mat)/vec)

 
 And from the ratios, I would like to rank the variables based on how 
many 
 times the variable being the highest among 4 of them (or the total 
number of 
 being the highest ratios, out of 1400 times).

Eh. I am stupid enough not to understand what you mean. Which variables? 
Do you mean maximum in each column?

 apply(ratiomat,2, max)
[1] 0.9686974 0.4097230 0.3085468

 
 From the 1400 by 4 dataset, I ran a principal component analysis and 
I'll use
 only the first PC for the calculation of the ratios.
 
 The PC (a vector) will has 4 values for each variables.
 
 The ratios actually representing the contribution of a variable divide 
by the 
 total contribution from the first PC.

I can not say much about principal components analysis above what is 
described in help page. 

 
 Does it make sense to you now? Thank you very much for giving a 
response. I 
 really appreciate it.

Not much. Reproducible code could be more informative then describing a 
problem by your words.

Regards
Petr

 
 Best regards,
 ayu
 
 
 
 
 
 From: Petr Pikal [via R] ml-node+1458931-701777...@n4.nabble.com
 
 Sent: Mon, 1 February, 2010 15:58:50
 Subject: Odp: How to repeat for function?
 
 Hi 
 few comments 
 
 [hidden email] napsal dne 01.02.2010 14:51:17: 
 
  
  Dear Users, 
  
  I have one problem here, I tried many time and even read a few notes 
on 
  writing function but still. 
  
  
  Can anyone help me on how to simplify Part B (please refer the 
 programming 
  below), so that I don't have to repeat the calculation of num and 
r 
 ? 
 
  
  
  
  Thank you very much..every help is very much appreciated... 
  
  
  ## Part A 
  n=1400 
  m=matrix(c(0,0,0,0),4,1) 
  m2=matrix(c(0,2,0,0),4,1) 
  
c4-matrix(c(1.0,0.2,-0.5,0.3,0.2,1,0.2,-0.5,-0.5,0.2,1,0.2,0.3,-0.5,0.2,1),
 4,4,byrow=T) 
  set.seed(428) 
  X=mvrnorm(n,m2,c4) 
  X.pca-princomp(X) 
  loadings(X.pca) 
  pc=X.pca$loadings[,1] 
  
  ## Â Part B 
  num1=rep(1:n) 
 
 is same as 
 num1 - 1:n 
 
  for(i in 1:n)num1[i]=pc[1]%*%X[i,1] 
 
 If I understand what the above code does I am a bit surprised 
 
 pc[1] is 
  pc[1] 
 [1] 0.525037 
 
 for each number in cycle 
 
 X[i,1] is again a number 
 
  X[1,1] 
 [1] 0.7512862 
  X[2,1] 
 [1] 0.5020333 
  
 
 so it basically  results in 
 
 pc[1] * X[,1] 
 
 which you can compute for all 4 columns by 
 
 kronecker(pc, X, *) 
 
 But I wonder if this is what you really want. 
 
 Maybe you shall think it over again and try with some smaller manageable 

 subset lit 
 
 smallX - X[1:5,] 
 
 do all your computation and if it does not produce what you want, 
specify 
 what you want. 
 
 Regards 
 Petr 
 
 
 
  num2=rep(1:n) 
  for(i in 1:n)num2[i]=pc[2]%*%X[i,2] 
  num3=rep(1:n) 
  for(i in 1:n)num3[i]=pc[3]%*%X[i,3] 
  num4=rep(1:n) 
  for(i in 1:n)num4[i]=pc[4]%*%X[i,4] 
  
  den=rep(1:n) 
  for(i in 1:n)den[i]=pc%*%X[i,] 
  
  
  r1=num1/den 
  r2=num2/den 
  r3=num3/den 
  r4=num4/den 
  MLAV=sum(r2r1  r2r3  r2r4) 
  MLAV 
  
  Best regards, 
  ayu 
  
  
  -- 
  View this message in context: 
http://n4.nabble.com/How-to-repeat-for-function-
  tp1458806p1458806.html 
  Sent from the R help mailing list archive at Nabble.com. 
  
  __ 
  [hidden email] 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. 
 
 __ 
 [hidden email] 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. 
 
 
 
 
 View message @ 
http://n4.nabble.com/How-to-repeat-for-function-tp1458806p1458931.html 
 To unsubscribe from How to repeat for function?, click here. 
 
 
 
 
 -- 
 View this message in context: 
http://n4.nabble.com/How-to-repeat-for-function-
 tp1458806p1459009.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] subset function unexpected behavior

2010-02-02 Thread Dennis Murphy
Hi:

Try this for your second loop instead:

for(s in school.list){
  print(s)
  print(subset(input.data, sch == s))
 }
[1] 1
  sch pop
1   1 100
2   1 200
[1] 2
  sch pop
3   2 300
4   2 400

Don't confound the 'sch' variable in your data frame with the
index in your loop :)

HTH,
Dennis

On Mon, Feb 1, 2010 at 8:17 PM, David Katz da...@davidkatzconsulting.comwrote:


 I was surprised to see this unexpected behavior of subset in a for loop. I
 looked in subset.data.frame and it seemed to me that both versions should
 work, since the subset call should be evaluated in the global environment -
 but perhaps I don't understand environments well enough. Can someone
 enlighten me? In any case, this is a bit of a gotcha for naive users of
 subset.

 input.data -
  data.frame(sch=c(1,1,2,2),
 pop=c(100,200,300,400))

 school.var - sch

 school.list - 1:2

 for(sch in school.list){
  print(sch)
  #do this before subset!:
  right.sch.p -
input.data[,school.var] == sch
  print(  subset(input.data,right.sch.p)) #this is what I expected
 }

 ## [1] 1
 ##   sch pop
 ## 1   1 100
 ## 2   1 200
 ## [1] 2
 ##   sch pop
 ## 3   2 300
 ## 4   2 400


 for(sch in school.list){
  print(sch)
  print(subset(input.data,input.data[,school.var] == sch)) #note - compact
 version fails!
 }

 ## [1] 1
 ##   sch pop
 ## 1   1 100
 ## 2   1 200
 ## 3   2 300
 ## 4   2 400
 ## [1] 2
 ##   sch pop
 ## 1   1 100
 ## 2   1 200
 ## 3   2 300
 ## 4   2 400

 --
 View this message in context:
 http://n4.nabble.com/subset-function-unexpected-behavior-tp1459535p1459535.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] Weighted SD

2010-02-02 Thread Patrick Burns

There is 'cov.wt'.  (If you have univariate
data, then you need to use 'as.matrix'.)

On 01/02/2010 20:32, Thomas Lumley wrote:

On Mon, 1 Feb 2010, David Winsemius wrote:



On Feb 1, 2010, at 12:37 PM, Антон Морковин wrote:


Dear all,
what function can be used to calculate weighted SD or/and SE¿

There's no such stuff in 'base' package.


Seems as though lm with a weights argument could be used fairly simply.



As I have pointed out from time to time, it depends on what the weights
are for -- are they precision weights, which lm() can handle, or
sampling weights, which it can't?

-tomas

Thomas Lumley Assoc. Professor, Biostatistics
tlum...@u.washington.edu University of Washington, Seattle



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


--
Patrick Burns
pbu...@pburns.seanet.com
http://www.burns-stat.com
(home of 'The R Inferno' and 'A Guide for the Unwilling S User')

__
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] character variables in substitute()

2010-02-02 Thread Dennis Murphy
Hi:

I played around with this earlier, but had only limited success. This is
what I
got; perhaps others can embellish this with more efficient (and correct)
code.

I couldn't get more than one expression in a line without overplotting.
Here's
an example:

plot(c(0, 1), c(0, 1))
text(0.5, 0.5, expression(R == 13.34859, P[m] == 2.53071))

# This makes sense, of course, because each expression is centered at
# the same point.

# You can put the text() statements along a row (pardon the crudity,
# and yes, there are no commas; it just makes the expressions more
# complicated):

plot(c(0, 1), c(0, 1))
text(0, 0.5, expression(R == 13.34859), adj = 0)
text(0.28, 0.5, expression(P[m] == 2.53071), adj = 0)
text(0.55, 0.5, expression(k[a] == 4.06000), adj = 0)
text(0.75, 0.5, expression(alpha[r] == 0.00719), adj = 0)

# However, one expression per line worked out OK (except for the
# desired five digit accuracy in k[a]...)

plot(c(0, 1), c(0, 1))
text(0.1, 0.9, expression(R == 13.34859), adj = 0)
text(0.1, 0.8, expression(P[m] == 2.53071), adj = 0)
text(0.1, 0.7, expression(k[a] == 4.06000), adj = 0)
text(0.1, 0.6, expression(alpha[r] == 0.00719), adj = 0)

# Trying multiple expressions in a plot title is equally challenging...here,
# only the first is rendered:

plot(c(0, 1), c(0, 1),
 main = expression(R == 13.34859, P[m] == 2.53071, k[a] == 4.06000,
 alpha[r] == 0.00719))

# The best I could do was paste text strings, but that's less
# than what we were hoping for...

plot(c(0, 1), c(0, 1),
  main = paste('R = 13.34859, ', 'P[m] = 2.53071, ', 'k[a] = 4.06000, ',
   'alpha[r] = 0.00719'), cex.main = 0.8)

I went through the plotmath demo and example and tried to find some
previous posts, but came up empty. There has to be a better way...

HTH,
Dennis


On Mon, Feb 1, 2010 at 9:50 PM, dkStevens david.stev...@usu.edu wrote:


 In trying to create a plotmath expression for plot labeling, such as

 R = 6, beta = 15

 where I want beta to be the Greek beta and, possibly, R in italics (like
 one
 would get in an explicit expression. The reason for this is that I want to
 write a string builder function that takes vectors of variable names and
 their values and return a plotmath expression for labeling a plot. One
 approach I tried is

 pname = c(R,beta)
 params = c(6,15)
 substitute(p == v,list(p = pname[i],v = format(params[i],digits=4))

 but this just copies the character strings in pname into the expression.
 Can
 anyone help me do what I want? How would I manage passing the resulting
 string back to the calling routine? Any help will be much appreciated.


 --
 View this message in context:
 http://n4.nabble.com/character-variables-in-substitute-tp1459566p1459566.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.


[R] Suppressing scientific notation on plot axis tick labels

2010-02-02 Thread Dimitri Shvorob

Is there a better alternative to

x  = c(1e7, 2e7)
x.lb = c(0,1e7,2e7) 
s.lb = format(x.lb, scientific = FALSE, big.mark = ,)
barplot(x, yaxt = n, ylab = ) 
axis(side = 2, at = x.lb, labels = s.lb)

(I am sure there is a better alternative to line 2 :)). 

Thank you.
-- 
View this message in context: 
http://n4.nabble.com/Suppressing-scientific-notation-on-plot-axis-tick-labels-tp1459697p1459697.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.


[R] how to use optim() or nlm() to solve three nonlinear equations

2010-02-02 Thread Nai-Wei Chen
Dear all,

I just know how to solve an eaquation by using optim() or nlm(). But, now, I 
have three nonlinear equations, 
how could we use optim() or nlm() to solve  a system of nonlinear equations in 
R?  Thank you so much.


Sincerely,

Joe

___ 
 您的生活即時通 - 溝通、娛樂、生活、工作一次搞定! 

[[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] character variables in substitute()

2010-02-02 Thread Eik Vettorazzi

Hi David,
there is a solution using bquote instead of substitute

expr-bquote(italic(.(pname[1]))==.(params[1])~, 
~.(as.name(pname[2]))==.(params[2]))

plot(1,1,main=expr)

hth.

dkStevens schrieb:
In trying to create a plotmath expression for plot labeling, such as 


R = 6, beta = 15

where I want beta to be the Greek beta and, possibly, R in italics (like one
would get in an explicit expression. The reason for this is that I want to
write a string builder function that takes vectors of variable names and
their values and return a plotmath expression for labeling a plot. One
approach I tried is

pname = c(R,beta)
params = c(6,15)
substitute(p == v,list(p = pname[i],v = format(params[i],digits=4))

but this just copies the character strings in pname into the expression. Can
anyone help me do what I want? How would I manage passing the resulting
string back to the calling routine? Any help will be much appreciated.


  


--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

__
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] Yield to Maturity using R

2010-02-02 Thread Madhavi Bhave


Dear R helpers,
 
 
Yesterday I had raised following query which was addressed by Mr Ellison. The 
query and the wonderful solution as provided by Mr. Ellison are as given below.
  
## PROBLEM
 
I am calculating the 'Yield to Maturity' for the Bond with following 
characteristics.
  
Its a $1000 face value, 3 year bond with 10% annual coupon and is priced at 
101. The yield to maturity can be calculated after solving the equation - 
  
1010 = [100 / (1+ytm)]  + [100 / (1+ytm)^2] + [ 1100 / (1 + ytm)^3]
  
This can be solved by trial and error method s.t. ytm = 9.601%. I wanted to 
find out how to solve this equation in R.
   
## SOLUTION 
 
Mr. Elisson had given me following wonderful solution 
 
f.ytm-function(ytm) 100 / (1+ytm)  +100 / ((1+ytm)^2) + 1100 / ((1 +
ytm)^3) -1010

uniroot(f.ytm, interval=c(0,25))  

#$root has the answer
 
And I got the answer as 9.601.
 
## _
 
I was just trying to generalize this solution to any equation and accordingly 
written a code as given below. 
 
The following input I will be reading using csv file and thus my equation will 
change if tenure or no_comp etc. changes. So taking into account the variable 
nature of the input, I am trying to write a generalized code.
 
## Input
 
price = 101   # Price of bond
tenure = 3  
no_comp = 1  # no of times coupon paid in a year.
coupon_rate = 0.10  # i.e. 10%
face_value  = 100
 
# Computations
 
coupon_payment = face_value * coupon_rate
cash_flow = c(rep(c(coupon_payemnt), (no_comp * tenure - 1)), face_value + 
coupon_payment)
cash_flow
 
## I am trying to customize the code as given by Mr Ellison.
 
f.ytm = function(ytm)
 
{
 
 for (i in 1 : (tenure * no_comp - 1))
 E = NULL
 F = NULL
 {
 E[i] = cash_flow[i]/(1+ytm)^i
 F = (sum(E) + (face_value + coupon_payment)/((1+ytm)^(tenure * no_comp))) - 
price
    }
}
 
solution = uniroot(f.ytm, interval=c(0,25))  
 
ytm = solution$root
 
However, when I execute this code I get following error.
 
 solution = uniroot(f.ytm, interval=c(0,25))  
Error in uniroot(f.ytm, interval = c(0, 25)) : f.lower = f(lower) is NA

Please guide. ytm should be 0.09601 (i.e. 9.601%)
 
 
with regards
 
Madhavi Bhave
 
 


  Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! 
http://downloads.yahoo.com/in/internetexplorer/
[[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] character variables in substitute()

2010-02-02 Thread Dennis Murphy
That's the trick, Eik! Nice job.

To return to the problem I was struggling with, it works with the following
incantation:

names - c('R', 'P', 'k', 'alpha')
vals - c(13.34859, 2.53071, 4.06000, 0.00719)
expr - bquote(.(names[1])==.(vals[1])~,
~.(as.name(names[2]))[m]==.(vals[2])~,

  ~.(as.name(names[3]))[a]==.(vals[3])~, ~.(as.name
(names[4]))[r]==.(vals[4]))
plot(c(0, 1), c(0, 1))
text(0.5, 0.5, expr)

Thanks for the valuable tip!
Dennis

On Tue, Feb 2, 2010 at 2:37 AM, Eik Vettorazzi 
e.vettora...@uke.uni-hamburg.de wrote:

 Hi David,
 there is a solution using bquote instead of substitute

 expr-bquote(italic(.(pname[1]))==.(params[1])~, ~.(as.name
 (pname[2]))==.(params[2]))
 plot(1,1,main=expr)

 hth.

 dkStevens schrieb:

  In trying to create a plotmath expression for plot labeling, such as
 R = 6, beta = 15

 where I want beta to be the Greek beta and, possibly, R in italics (like
 one
 would get in an explicit expression. The reason for this is that I want to
 write a string builder function that takes vectors of variable names and
 their values and return a plotmath expression for labeling a plot. One
 approach I tried is

 pname = c(R,beta)
 params = c(6,15)
 substitute(p == v,list(p = pname[i],v = format(params[i],digits=4))

 but this just copies the character strings in pname into the expression.
 Can
 anyone help me do what I want? How would I manage passing the resulting
 string back to the calling routine? Any help will be much appreciated.





 --
 Eik Vettorazzi
 Institut für Medizinische Biometrie und Epidemiologie
 Universitätsklinikum Hamburg-Eppendorf

 Martinistr. 52
 20246 Hamburg

 T ++49/40/7410-58243
 F ++49/40/7410-57790


 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide
 http://www.R-project.org/posting-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Memory Problem

2010-02-02 Thread Meenakshi

Hi,

When I run the repeat loop in R for large dataset, I got Memory problem. 
How can I solve these problem. 
-- 
View this message in context: 
http://n4.nabble.com/Memory-Problem-tp1459740p1459740.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.


[R] Abstract submission deadline, useR! 2010

2010-02-02 Thread Katharine Mullen
The abstract submission deadline for the R Users Conference, useR! 2010, 
is just one month away.


Submission deadline: 2010-03-01

Early registration will also close on 2010-03-01.

Now is the perfect time to prepare an abstract presenting innovations or 
exciting applications of R. The call for abstracts along with the link for 
submission is available at:

http://www.R-project.org/useR-2010/#Call

This meeting of the R user community will take place at the Gaithersburg, 
Maryland, USA campus of the National Institute of Standards and Technology 
(NIST), July 21-23, 2010.


The conference schedule is comprised of invited lectures and 
user-contributed sessions as well as half-day tutorials presented by R 
experts on July 20, 2010, prior to the conference.


Invited speakers will include
Mark Handcock, Frank Harrell Jr, Friedrich Leisch, Michael Meyer,
Richard Stallman, Luke Tierney, and Diethelm Wuertz.

The full spectrum of conference information is available from the webpage:
http://www.R-project.org/useR-2010/

We hope to meet you in Gaithersburg!

Kate Mullen, for the organizing committee

___
r-annou...@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-announce

__
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] [R-pkgs] Major update: mboost 2.0-0 released

2010-02-02 Thread Benjamin Hofner

Dear useRs,

we are happy to announce the release of mboost 2.0-0 on CRAN:

http://cran.r-project.org/package=mboost

This version contains major updates and changes to the implementation of 
the main algorithm. Some slight changes to the user-interface where 
necessary. Please consult the manual and the list of CHANGES below.


The package 'mboost' (Model-based Boosting) implements boosting for 
optimizing general risk functions utilizing component-wise (penalized) 
least squares estimates or regression trees as base-learners for fitting 
generalized linear, additive and interaction models to potentially 
high-dimensional data.


A big variety of models can be investigated using 'mboost' including 
survival models, expectile regression models, ordinal regression models 
as well as standard models such as simple linear models. In all cases, 
the predictor can be specified very flexible using linear, smooth, 
random and spatial effects as well as decision trees or an arbitrary 
combination suiting the intention of the researcher.


For more details and a nice example showing some of the functionality of 
'mboost' see ?mboost-package.


We appreciate any feedback.

   mboost development team

___


CHANGES in `mboost' VERSION 2.0-0 (2010-02-01)

  o  generic implementation of component-wise functional gradient
 boosting in `mboost_fit', specialized code for linear,
 additive and interaction models removed

  o  new families available for ordinal, expectile and censored
 regression

  o  computations potentially based on package Matrix
 (reduces memory usage)

  o  various speed improvements

  o  added interface to extract selected base-learners (selected())

  o  added interface for parallel computations in cvrisk with
 arbitrary packages (e.g. multicore, snow)

  o  added which argument in predict and coef functions and improved
 usability of which in plot-function. Users can specify which as
 numeric value or as a character string

  o  added function cv() to generate matrices for k-fold
 cross-validation, subsampling and bootstrap

  o  new function stabsel() for stability selection with error control

  o  added function model.weights() to extract the weights

  o  added interface to expand model by increasing mstop in
 model[mstop]

  o  alternative definition of degrees of freedom available

  o  Interface changes:

 - class definition / Family() arguments changed
 - changed behavior of subset method (model[mstop]). Object
   is directly altered and not duplicated
 - argument center in bols replaced with intercept
 - argument z in base-learners replaced with by
 - bns and bss deprecated


--
**
Dipl.-Stat. Benjamin Hofner

Institut für Medizininformatik, Biometrie und Epidemiologie
Friedrich-Alexander-Universität Erlangen-Nürnberg
Waldstr. 6 - 91054 Erlangen - Germany

benjamin.hof...@imbe.med.uni-erlangen.de

http://www.imbe.med.uni-erlangen.de/~hofnerb/
http://www.benjaminhofner.de

___
R-packages mailing list
r-packa...@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-packages

__
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] Suppressing scientific notation on plot axis tick labels

2010-02-02 Thread Dimitri Shvorob

Ruben Roa has kindly suggested using 'scipen' option - cf.

 fixed notation will be preferred unless it is more than ‘scipen’ digits
 wider.

However, 

options(scipen = 50)
x  = c(1e7, 2e7)
barplot(x) 

still does not produce the desired result.

-- 
View this message in context: 
http://n4.nabble.com/Suppressing-scientific-notation-on-plot-axis-tick-labels-tp1459697p1459789.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.


[R] 3D plot of following data

2010-02-02 Thread walter.djuric
Hello R-experts, 

I am having difficulties with 3D plotting (i.e. the evolution of various 
forward curves through time). 

I have two comma seperated files both ordered by date (in the first column) one 
containing contracts (meaning forward delivery months from YEAR_  Letter F 
... January through letter Z ... December) and the other holding the closing 
price of the respective contract on the day also defined in the first column 
(see attachments). 

What I would like to do is plot a three dimensional figure with trade day 
(date) on the X-axis, contract on the Y-axis and the price of the forward 
contract being the z-value. 
I am quite a newbie and did not manage to merge these two files in a logic way, 
so that R could do a 3D plot. 

Any help would be appreciated. 
--
WD__
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] how to use optim() or nlm() to solve three nonlinear equations

2010-02-02 Thread Berend Hasselman


Nai-Wei Chen wrote:
 
 I just know how to solve an eaquation by using optim() or nlm(). But, now,
 I have three nonlinear equations, 
 how could we use optim() or nlm() to solve  a system of nonlinear
 equations in R?  Thank you so much.
 

You don't use general optimize routines to solve a set of nonlinear
equations.
It is not efficient and it is not recommended.

There are two packages: nleqslv and BB, that you can use to solve non linear
equation systems.
Both are available on CRAN.

/B
-- 
View this message in context: 
http://n4.nabble.com/how-to-use-optim-or-nlm-to-solve-three-nonlinear-equations-tp1459716p1459803.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] Solving an optimization problem: selecting an quot; optimalquot; subset

2010-02-02 Thread Hans W Borchers


Erwin Kalvelagen-2 wrote:
 
 Hans W Borchers hwborchers at googlemail.com writes:
 # Prepare inputs for MILP solver
 obj - c(rep(0, n), 0, 1, 1, 0)
 typ - c(rep(B, n), B, C, C, B)
 mat - matrix(c(s, -z, -1, 1, 0,# a = a_p + a_m
 rep(0, n), 1, 0, 0, 0,  # constant term
 rep(0, n), 0, 1, 0, -M, # a_p = M * d0
 rep(0, n), 0, 0, 1, M,  # a_m = M * (d0-1)
 rep(1, n), 0, 0, 0, 0), # subset size = k
 nrow=5, byrow=T)
 dir - c(==, ==, =, =, =)
 rhs - c(0, 1, 0, M, k)
 max - FALSE
 
 You can drop the binary variable d0. 
 The condition one of a_p,a_m is zero holds
 automatically as we are minimizing a_p+a_m.
 
 
 Erwin Kalvelagen
 
 

Right; for me adding M and d0 is kind of a reflex, but that is only
necessary when  a_p + a_m  is used as an intermediate result.

One more remark: I saw some spurious behavior with both solvers (Rsymphony,
Rglpk) -- that is, slightly different results in different runs.  It could
relate to the tolerance with which these solvers compare and identify
solutions.  At the moment I don't know how to change the tolerance as a
parameter.

I guess this will not happen when using a more powerful solver such as
CPLEX.

Hans Werner

-- 
View this message in context: 
http://n4.nabble.com/Solving-an-optimization-problem-selecting-an-optimal-subset-tp1446084p1459843.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] Yield to Maturity using R

2010-02-02 Thread Eik Vettorazzi

Hi Madhavi,
the error message means, that your function returns NA evaluated at the 
lower limit of the search interval.

try f.ytm(0) to check that.

I think,

for (i in 1 : (tenure * no_comp - 1))
E = NULL
F = NULL
{
E[i] = cash_flow[i]/(1+ytm)^i
F = (sum(E) + (face_value + coupon_payment)/((1+ytm)^(tenure * no_comp))) - 
price
   }

will not return what you expected, since the code evaluates solely E 
=NULL (tenure * no_comp - 1) times. (the opening curly bracket is misplaced)


hth



Madhavi Bhave schrieb:

Dear R helpers,
 
 
Yesterday I had raised following query which was addressed by Mr Ellison. The query and the wonderful solution as provided by Mr. Ellison are as given below.
  
## PROBLEM
 
I am calculating the 'Yield to Maturity' for the Bond with following characteristics.
  
Its a $1000 face value, 3 year bond with 10% annual coupon and is priced at 101. The yield to maturity can be calculated after solving the equation - 
  
1010 = [100 / (1+ytm)]  + [100 / (1+ytm)^2] + [ 1100 / (1 + ytm)^3]
  
This can be solved by trial and error method s.t. ytm = 9.601%. I wanted to find out how to solve this equation in R.
   
## SOLUTION 
 
Mr. Elisson had given me following wonderful solution 
 
f.ytm-function(ytm) 100 / (1+ytm)  +100 / ((1+ytm)^2) + 1100 / ((1 +

ytm)^3) -1010

uniroot(f.ytm, interval=c(0,25))  


#$root has the answer
 
And I got the answer as 9.601.
 
## _
 
I was just trying to generalize this solution to any equation and accordingly written a code as given below. 
 
The following input I will be reading using csv file and thus my equation will change if tenure or no_comp etc. changes. So taking into account the variable nature of the input, I am trying to write a generalized code.
 
## Input
 
price = 101   # Price of bond
tenure = 3  
no_comp = 1  # no of times coupon paid in a year.

coupon_rate = 0.10  # i.e. 10%
face_value  = 100
 
# Computations
 
coupon_payment = face_value * coupon_rate

cash_flow = c(rep(c(coupon_payemnt), (no_comp * tenure - 1)), face_value + 
coupon_payment)
cash_flow
 
## I am trying to customize the code as given by Mr Ellison.
 
f.ytm = function(ytm)
 
{
 
 for (i in 1 : (tenure * no_comp - 1))

 E = NULL
 F = NULL
 {
 E[i] = cash_flow[i]/(1+ytm)^i
 F = (sum(E) + (face_value + coupon_payment)/((1+ytm)^(tenure * no_comp))) - 
price
}
}
 
solution = uniroot(f.ytm, interval=c(0,25))  
 
ytm = solution$root
 
However, when I execute this code I get following error.
 
  
solution = uniroot(f.ytm, interval=c(0,25))  


Error in uniroot(f.ytm, interval = c(0, 25)) : f.lower = f(lower) is NA

Please guide. ytm should be 0.09601 (i.e. 9.601%)
 
 
with regards
 
Madhavi Bhave
 
 



  Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! 
http://downloads.yahoo.com/in/internetexplorer/
[[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.
  


--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf

Martinistr. 52
20246 Hamburg

T ++49/40/7410-58243
F ++49/40/7410-57790

__
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] hvcluster() with distance method from vegdist(), package = vegan

2010-02-02 Thread Kay Cichini

hello,

i'd be happy if someone could provide help with the following problem:

i have a dist.matrix that comes from vegdist() function of the vegan
package. the used method = horn is not accepted as argument in
hvcluster(...,dist.method=...). 

is there a way to incorporate the method horn in hvcluster()?

thanks in advance!

yours,
kay
-- 
View this message in context: 
http://n4.nabble.com/hvcluster-with-distance-method-from-vegdist-package-vegan-tp1459859p1459859.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] hvcluster() with distance method from vegdist(), package = vegan

2010-02-02 Thread Kay Cichini

sorry, it should say pvclust(), of course...
-- 
View this message in context: 
http://n4.nabble.com/hvcluster-with-distance-method-from-vegdist-package-vegan-tp1459859p1459865.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] Yield to Maturity using R

2010-02-02 Thread Madhavi Bhave
Dear Sir,
 
Thank you for valuable guidance. Though I have been using R occassionally, it 
was limited to some basics and that way I am new to R. As suggested by you, I 
have gone through the said chapter of Introduction to R manual, though I have 
some urgent comittments to meet.
 
I have tried writing function as given below.
 
 
f = function(price, tenure, no_comp, coupon_rate, face_value)
 
{
coupon_payment = face_value * coupon_rate / no_comp
cash_flow = c(rep(c(coupon_payment), (no_comp * tenure - 1)), face_value + 
coupon_payment)
 
E = NULL
 for (i in 1 : (tenure * no_comp - 1))
  {
  E[i] = cash_flow[i]/(1+ytm)^i
  }
 
 F = NULL
  {
  F = sum(E) + ((face_value + coupon_payment)/(1+ytm)^(no_comp * tenure)) - 
price
  }
 
return(data.frame(S = uniroot.all(F, interval=c(0,25  
  
}
 
output = f(1010, 3, 1, 0.10, 1000)
 
##  End of code
 
However, when I try to execute the same, I get following error. 
 
Error: object 'ytm' not found

My objective is to find ytm itself and I am not able to figure out where I am 
going wrong and how to overcome the same.
 
Regards
 
Madhavi

--- On Tue, 2/2/10, Dennis Murphy djmu...@gmail.com wrote:


From: Dennis Murphy djmu...@gmail.com
Subject: Re: [R] Yield to Maturity using R
To: Madhavi Bhave madhavi_bh...@yahoo.com
Date: Tuesday, 2 February, 2010, 3:49 AM


Hi:


On Tue, Feb 2, 2010 at 3:01 AM, Madhavi Bhave madhavi_bh...@yahoo.com wrote:



Dear R helpers,
 
 
Yesterday I had raised following query which was addressed by Mr Ellison. The 
query and the wonderful solution as provided by Mr. Ellison are as given below.
  
## PROBLEM
 
I am calculating the 'Yield to Maturity' for the Bond with following 
characteristics.
  
Its a $1000 face value, 3 year bond with 10% annual coupon and is priced at 
101. The yield to maturity can be calculated after solving the equation - 
  
1010 = [100 / (1+ytm)]  + [100 / (1+ytm)^2] + [ 1100 / (1 + ytm)^3]
  
This can be solved by trial and error method s.t. ytm = 9.601%. I wanted to 
find out how to solve this equation in R.
   
## SOLUTION
 
Mr. Elisson had given me following wonderful solution
 
f.ytm-function(ytm) 100 / (1+ytm)  +100 / ((1+ytm)^2) + 1100 / ((1 +
ytm)^3) -1010

uniroot(f.ytm, interval=c(0,25)) 

#$root has the answer
 
And I got the answer as 9.601.
 
## _
 
I was just trying to generalize this solution to any equation and accordingly 
written a code as given below.
 
The following input I will be reading using csv file and thus my equation will 
change if tenure or no_comp etc. changes. So taking into account the variable 
nature of the input, I am trying to write a generalized code.
 
## Input
 
price = 101   # Price of bond
tenure = 3 
no_comp = 1  # no of times coupon paid in a year.
coupon_rate = 0.10  # i.e. 10%
face_value  = 100
 
# Computations
 
coupon_payment = face_value * coupon_rate
cash_flow = c(rep(c(coupon_payemnt), (no_comp * tenure - 1)), face_value + 
coupon_payment)
cash_flow
 
## I am trying to customize the code as given by Mr Ellison.
 
f.ytm = function(ytm)
 
{
 
 for (i in 1 : (tenure * no_comp - 1))
 E = NULL
 F = NULL
 {
 E[i] = cash_flow[i]/(1+ytm)^i
 F = (sum(E) + (face_value + coupon_payment)/((1+ytm)^(tenure * no_comp))) - 
price
    }
}
 

For this to work, tenure, no_comp, cash_flow, face_value and coupon_payment 
have to be
visible to the function - i.e., they either have to be in the function's 
calling environment
or in the global environment. These are called 'free variables' under the 
lexical
scoping rules of R. (Welcome to function writing :)  

You might want to look a little more closely at uniroot(), especially the 
conventions
it requires for the *functions* it can evaluate. You want the body of what you 
send
to uniroot() for evaluation to be a function of a single variable. Your 
previously supplied
solution meets that requirement. This one doesn't (yet).

Moreover, it appears that E[i] is never used and nothing is returned from 
f.ytm. I'd
suggest an excursion into R function writing fundamentals. Start with Ch. 10 of
the Introduction to R manual.

HTH,
Dennis


solution = uniroot(f.ytm, interval=c(0,25)) 
 
ytm = solution$root
 
However, when I execute this code I get following error.
 
 solution = uniroot(f.ytm, interval=c(0,25)) 
Error in uniroot(f.ytm, interval = c(0, 25)) : f.lower = f(lower) is NA

Please guide. ytm should be 0.09601 (i.e. 9.601%)
 
 
with regards
 
Madhavi Bhave
 
 


     Your Mail works best with the New Yahoo Optimized IE8. Get it NOW! 
http://downloads.yahoo.com/in/internetexplorer/
       [[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.





[[elided Yahoo spam]]

[[alternative HTML version 

Re: [R] Memory Problem

2010-02-02 Thread Uwe Ligges



On 02.02.2010 11:33, Meenakshi wrote:


Hi,

When I run the repeat loop in R for large dataset, I got Memory problem.
How can I solve these problem.


buy more memory, bigger machine, more efficient programming, import of 
only relevant data, use of specific tools, .. or in other words: 
Depends on your problem and please do read the posting guide.


Uwe Ligges

__
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] 3D plot of following data

2010-02-02 Thread Uwe Ligges
Since your files did not come through the mail list, I'd suggest to put 
them on some webside and provide a link.


Uwe Ligges



On 02.02.2010 13:01, walter.dju...@chello.at wrote:

Hello R-experts,

I am having difficulties with 3D plotting (i.e. the evolution of various 
forward curves through time).

I have two comma seperated files both ordered by date (in the first column) one containing contracts 
(meaning forward delivery months from YEAR_  Letter F ... January through letter 
Z ... December) and the other holding the closing price of the respective contract on the 
day also defined in the first column (see attachments).

What I would like to do is plot a three dimensional figure with trade day 
(date) on the X-axis, contract on the Y-axis and the price of the forward 
contract being the z-value.
I am quite a newbie and did not manage to merge these two files in a logic way, 
so that R could do a 3D plot.

Any help would be appreciated.
--
WD



__
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] Biclustering / Co-clustering in more than 2 dimensions

2010-02-02 Thread Tim Smith
Hi,

I was wondering if there existed a package in R that would bicluster / 
co-cluster in more than 2 dimensions.
thanks!


  
[[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] Subtracting time series

2010-02-02 Thread Nick Torenvliet
Hi all,

I've got a time series object (xts) called table.  Table contains closing
price and volume for each market day of 2009 on a given equity.

I'd like to get another xts object, say table2, that contains for each
market day holds the close of that day minus the close of the day before and
the volume of that day minus the volume of the day before.

So

table2 - table[x,] - table[(x-1),]

But I can't quit get the syntax, any help would be appreciated.

Nick

[[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] strange behaviour: recognition of decimal numbers by 'which'

2010-02-02 Thread J . delasHeras


It is a strange behaviour in that I did not expect it... but I am sure  
there is a simple explanation for it and it'll have to do with the way  
numbers are stored in R, but it's caught me by surprise and I don't  
find it obvious.


Here's a simplified example reproducing the behaviour I encountered:

I create an empty vector, and I fill it with a sequence of numbers: 0,  
0.005, 0.01, 0.015, 0.02, etc... until 0.1.
(In my real code this is just a way to store certain values when  
certain conditions are met etc etc)
Then I ask which element contains teh value 0.01. Ok. Same with 0.02.  
But when I ask about 0.03 or above... the answer is none. But I can  
see 0.03 in my vector, it is there!


This must be because of the value stored internally. Indeed, if I do:

v-0.03, when I reach the value that appeared to contain 0.03, I don't  
obtain zero, but 3.47e-18


why is this?
what is the recommended way to overcome this?
Interestingly, if I store the values as character, then I can match  
them fine...


Below is the code, and my sessionInfo() output.

Thanks!

Jose de las Heras


code example:
#v-vector(mode=character)
v-c()
i-0
while (i = 0.1)
  {
  v-c(v,i)
  i-i+0.005
  }
v
which(v==0.01)
which(v==0.02)
which(v==0.03)




sessionInfo()

R version 2.10.0 (2009-10-26)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

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

other attached packages:
[1] biomaRt_2.2.0

loaded via a namespace (and not attached):
[1] RCurl_1.3-1  tools_2.10.0 XML_2.6-0



--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

__
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] strange behaviour: recognition of decimal numbers by 'which'

2010-02-02 Thread Erik Iverson

FAQ 7.31

j.delashe...@ed.ac.uk wrote:


It is a strange behaviour in that I did not expect it... but I am sure 
there is a simple explanation for it and it'll have to do with the way 
numbers are stored in R, but it's caught me by surprise and I don't find 
it obvious.


Here's a simplified example reproducing the behaviour I encountered:

I create an empty vector, and I fill it with a sequence of numbers: 0, 
0.005, 0.01, 0.015, 0.02, etc... until 0.1.
(In my real code this is just a way to store certain values when certain 
conditions are met etc etc)
Then I ask which element contains teh value 0.01. Ok. Same with 0.02. 
But when I ask about 0.03 or above... the answer is none. But I can see 
0.03 in my vector, it is there!


This must be because of the value stored internally. Indeed, if I do:

v-0.03, when I reach the value that appeared to contain 0.03, I don't 
obtain zero, but 3.47e-18


why is this?
what is the recommended way to overcome this?
Interestingly, if I store the values as character, then I can match 
them fine...


Below is the code, and my sessionInfo() output.

Thanks!

Jose de las Heras


code example:
#v-vector(mode=character)
v-c()
i-0
while (i = 0.1)
  {
  v-c(v,i)
  i-i+0.005
  }
v
which(v==0.01)
which(v==0.02)
which(v==0.03)




sessionInfo()

R version 2.10.0 (2009-10-26)
i386-pc-mingw32

locale:
[1] LC_COLLATE=English_United Kingdom.1252
[2] LC_CTYPE=English_United Kingdom.1252
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C
[5] LC_TIME=English_United Kingdom.1252

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

other attached packages:
[1] biomaRt_2.2.0

loaded via a namespace (and not attached):
[1] RCurl_1.3-1  tools_2.10.0 XML_2.6-0





__
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] Biclustering / Co-clustering in more than 2 dimensions

2010-02-02 Thread Gábor Csárdi
Hi Tim,

maybe you are looking for something like this:
http://www.nature.com/nbt/journal/v26/n5/full/nbt1397.html
It is relatively easy to implement in R, I think.

Best,
Gabor

On Tue, Feb 2, 2010 at 3:44 PM, Tim Smith tim_smith_...@yahoo.com wrote:
 Hi,

 I was wondering if there existed a package in R that would bicluster / 
 co-cluster in more than 2 dimensions.
 thanks!



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




-- 
Gabor Csardi gabor.csa...@unil.ch 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] Subtracting time series

2010-02-02 Thread Achim Zeileis

On Tue, 2 Feb 2010, Nick Torenvliet wrote:


Hi all,

I've got a time series object (xts) called table.  Table contains closing
price and volume for each market day of 2009 on a given equity.

I'd like to get another xts object, say table2, that contains for each
market day holds the close of that day minus the close of the day before and
the volume of that day minus the volume of the day before.

So

table2 - table[x,] - table[(x-1),]


This does not do what you want because xts is smart and aligns along the 
time index.



But I can't quit get the syntax, any help would be appreciated.


Look at diff() and lag() and their respective methods for xts series.
Z


Nick

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


[R] finding files whose name does NOT contain a given character

2010-02-02 Thread mauede
Unluckily I dela with miRNA files whose name may contain the character *.
Because of the special meaning of * I have to remove it.
I found out how to make list.files() extract only those file names which 
contain a *
Namely:
# list.files(pattern=\\*) 

Now I have to process all files whose name does NOT contain the character *.
I cannot have list.files() extract all files  whose name does NOT match 
pattern=\\*
I tried using ^ in such a pattern but nothing is returned.
Any suggestion is welcome.

Thank you so much,
Maura


tutti i telefonini TIM!


[[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] Plot - specification for grid of x axis

2010-02-02 Thread Trafim Vanishek
Dear all,

I have a simple question for which I cannot find the answer.

I need to make an easy plot, but for the x axis I need to be able to specify
by myself the division of x axis from x[,1] either every single observation,
or every 5th, or 10th or 20th

x - matrix(data=NA, nrow=100, ncol=2)
x[,1]-seq(1,100,1)
x[,2]-rnorm(100)

Thanks a lot 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.


Re: [R] finding files whose name does NOT contain a given character

2010-02-02 Thread Peter Dalgaard
mau...@alice.it wrote:
 Unluckily I dela with miRNA files whose name may contain the character *.
 Because of the special meaning of * I have to remove it.
 I found out how to make list.files() extract only those file names which 
 contain a *
 Namely:
 # list.files(pattern=\\*) 
 
 Now I have to process all files whose name does NOT contain the character *.
 I cannot have list.files() extract all files  whose name does NOT match 
 pattern=\\*
 I tried using ^ in such a pattern but nothing is returned.
 Any suggestion is welcome.

That'll be something like pattern=^[^*]*$ (untested, I don't think I
have any filenames with * inside...)

Alternatively, you might try

allfiles - list.files()
withstar - allfiles[grepl(\\*, allfiles)]
nostar - allfiles[!grepl(\\*, allfiles)]

-- 
   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
~~ - (p.dalga...@biostat.ku.dk)  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] finding files whose name does NOT contain a given character

2010-02-02 Thread Erik Iverson



mau...@alice.it wrote:

Unluckily I dela with miRNA files whose name may contain the character *.
Because of the special meaning of * I have to remove it.
I found out how to make list.files() extract only those file names which contain a 
*
Namely:
# list.files(pattern=\\*) 


Now I have to process all files whose name does NOT contain the character *.
I cannot have list.files() extract all files  whose name does NOT match 
pattern=\\*
I tried using ^ in such a pattern but nothing is returned.
Any suggestion is welcome.

Thank you so much,
Maura




Maybe ?setdiff could even help here ...



tutti i telefonini TIM!


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


[R] Finding the difference between two vectors

2010-02-02 Thread anna

Hello everyone,
I have two vectors having only one element different:
   vector1 vector2   
vector1

   TWC TWC
TWC
   VFC  TWX
NA 
  VIA/B VFC 
VFC
  WHR VIA/B
VIA/B
   WPO WHR   -WHR
   WYN WPO
WPO
   WYNN  WYN  
WYN
   YUMWYNN
WYNN
   NA   YUM  
YUM
In that case, in the first vector, the value twx is missing . What I want to
do is doing the following avoiding loop:
putting the NA row in front of the TWX row as this would be the row where
the value is missing. I don't know if there is any function doing this. I
thought about using a which() function to retrieve all the missing elements
index ( twx, 1 here) and insert them in the right index in the first vector
but how can I insert in a vector, is there an appropriated function? thank
you

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Finding-the-difference-between-two-vectors-tp1460020p1460020.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] merging data frames gives all NAs

2010-02-02 Thread James Rome

David,

Now the code is:
for (j in seq_along(rwy)) { # subset the data and merge them
ar4rw = ar4rw - subset(arrgnd, arrgnd$Runway==rwy[j])
if(j == 1) {
arrw = ar4rw
}
else {
arrw = merge(arrw, ar4rw)
}
}

I attach the data. I needed 500 rows to get both runways in rwy.

The suggestions did not help much, but did get rid of the row of NAs in
ar4rw. Why?
When I run through the loop for 2 runways, I get

# j = 1, Runway = 31L
Browse[1] arrw[1:3,]
DateTime Date month hour minute quarter weekday IATA ICAO Flight
552 1/1/09 23:03 2009-01-01 1 23 3 92 5 AA AAL AAL22
563 1/1/09 23:17 2009-01-01 1 23 17 93 5 DL DAL DAL242
565 1/1/09 23:24 2009-01-01 1 23 24 93 5 DL DAL DAL624
AircraftType Tail Arrived STA Runway FromTo Delay
552 B762 N329AA 23:03:35 23:10 * 31L* LAX /JFK 0
563 B763 N1611B 23:17:37 23:46 31L KATL /KJFK 0
565 B752 N654DL 23:24:04 23:48 31L LAS /JFK 0
Operator dq gw
552 AMERICAN AIRLINES 2009-01-01 92 1
563 DELTA AIR LINES 2009-01-01 93 1
565 DELTA AIR LINES 2009-01-01 93 1
# j = 2 Runway=31R
Browse[1] ar4rw[1:3,]
DateTime Date month hour minute quarter weekday IATA ICAO Flight
529 1/1/09 21:46 2009-01-01 1 21 46 87 5 TA TAI TAI570
530 1/1/09 21:48 2009-01-01 1 21 48 87 5 AA AAL AAL2018
531 1/1/09 21:50 2009-01-01 1 21 50 87 5 BA BAW BAW183
AircraftType Tail Arrived STA Runway FromTo Delay
529 A320 N496TA 21:46:58 22:30 * 31R* MSLP /KJFK 0
530 B752 N621AM 21:48:43 21:50 31R TLPL /JFK 0
531 B744 G-CIVI 21:50:26 22:50 31R EGLL /KJFK 0
Operator dq gw
529 TACA INTERNATIONAL AIRLINES 2009-01-01 87 1
530 AMERICAN AIRLINES 2009-01-01 87 1
531 BRITISH AIRWAYS 2009-01-01 87 1
# But the merge gives all NAs!
] arrw[1:3,]
DateTime Date month hour minute quarter weekday IATA ICAO Flight
NA NA NA NA NA NA NA NA NA NA NA
NA.1 NA NA NA NA NA NA NA NA NA NA
NA.2 NA NA NA NA NA NA NA NA NA NA
AircraftType Tail Arrived STA Runway FromTo Delay Operator dq gw
NA NA NA NA NA NA NA NA NA NA NA
NA.1 NA NA NA NA NA NA NA NA NA NA
NA.2 NA NA NA NA NA NA NA NA NA NA

Thanks,
Jim Rome

On Feb 1, 2010, at 5:30 PM, David Winsemius wrote:



On Feb 1, 2010, at 5:16 PM, James Rome wrote:


Dear kind R helpers,

I have a vector of runway names in rwy (31R, 31L,... the number
is user selectable)
arrgnd is a data frame with data for all flights and all runways,
with a Runway column.
I am trying to subset arrgnd into a dat frame for each selected
runway, and then combine them back together using the following code:

for (j in 1:nr) { # nr = number of user-selected runways


Safer would be:

for (j in seq_along(rwy) {


ar4rw = arrgnd[arrgnd$Runway==rwy[j],]


Clearer would be :

ar4rw - subset(arrgnd, Runway= j) # and I think the NA line's will
also disappear.

^ == ^




if (j == 1) {
arrw = ar4rw
}
else {
arrw = merge(arrw, ar4rw)
}
}


You really should give us something like:

dput(rwy)
dput( head(arrgnd, 10) )


but, the merge step gives me a data frame with all NAs. In addition,
ar4rw always gets a row with NAs at the start, which I do not
understand. There are no rows with all NAs in the arrgnd data frame.
 ar4rw[1:2,] # first time through for 31R
DateTime Date month hour minute quarter weekday IATA ICAO Flight
NA NA NA NA NA NA NA NA NA NA NA
529 1/1/09 21:46 2009-01-01 1 21 46 87 5 TA TAI TAI570
AircraftType Tail Arrived STA Runway FromTo Delay
NA NA NA NA NA NA NA NA
529 A320 N496TA 21:46:58 22:30 31R MSLP /KJFK 0
Operator dq gw
NA NA NA NA
529 TACA INTERNATIONAL AIRLINES 2009-01-01 87 1

 ar4rw[1:2,] # second time through for 31L
DateTime Date month hour minute quarter weekday IATA ICAO Flight
NA NA NA NA NA NA NA NA NA NA NA
552 1/1/09 23:03 2009-01-01 1 23 3 92 5 AA AAL AAL22
AircraftType Tail Arrived STA Runway FromTo Delay Operator
NA NA NA NA NA NA NA NA NA
552 B762 N329AA 23:03:35 23:10 31L LAX /JFK 0 AMERICAN AIRLINES
dq gw
NA NA NA

But after the merge, I get all NAs. What am I doing wrong?


The data layout gets mangled and I cannot tell what rows are being
matched to what. Use dput to convey an unambiguous, and easily
replicated example.


Thanks,
Jim Rome

552 2009-01-01 92 1

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] 3D plot of following data

2010-02-02 Thread Uwe Ligges



On 02.02.2010 16:01, walter.dju...@chello.at wrote:

Here they are for now for you.
And I will put them somewhere in a few minutes and poost the link.



No need to do so. If you really want to use 3D plots (which I doubt you 
really want since you could do better in 2D using dotcharts or so):


setwd('d:/')
#READ IN Contracts
NG.contracts - read.csv('NG_contracts.csv', header=FALSE, sep=;, 
na.string=)

NG.contracts$V1 - as.Date(NG.contracts$V1,format='%d.%m.%Y')
#READ IN Values
NG.values - read.csv('NG_values.csv', header=FALSE, sep=;, na.string=?)
NG.values$V1 - as.Date(NG.values$V1, format='%d.%m.%Y')



## new stuff by UL:

NG.valuesl - reshape(NG.values, direction=long, varying=list(2:32), 
idvar=V1)
NG.contractsl - reshape(NG.contracts, direction=long, 
varying=list(2:32), idvar=V1)

NG - NG.valuesl[,c(V1,V2)]
colnames(NG) - c(Date, value)
rownames(NG) - NULL
NG$contract - NG.contractsl[,V2]


## two ways, one for nice viewing, one for easier printout:

library(rgl)
plot3d(NG$Date, NG$contract, NG$value)

library(scatterplot3d)
scatterplot3d(NG$Date, NG$contract, NG$value, pch=20)

Now you need to prettify exes etc.


Uwe Ligges






Greetings,
Walter

 Uwe Liggeslig...@statistik.tu-dortmund.de  schrieb:

Since your files did not come through the mail list, I'd suggest to put
them on some webside and provide a link.

Uwe Ligges



On 02.02.2010 13:01, walter.dju...@chello.at wrote:

Hello R-experts,

I am having difficulties with 3D plotting (i.e. the evolution of various 
forward curves through time).

I have two comma seperated files both ordered by date (in the first column) one containing contracts 
(meaning forward delivery months from YEAR_   Letter F ... January through letter 
Z ... December) and the other holding the closing price of the respective contract on the 
day also defined in the first column (see attachments).

What I would like to do is plot a three dimensional figure with trade day 
(date) on the X-axis, contract on the Y-axis and the price of the forward 
contract being the z-value.
I am quite a newbie and did not manage to merge these two files in a logic way, 
so that R could do a 3D plot.

Any help would be appreciated.
--
WD



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


--
mfg
WD


__
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] finding files whose name does NOT contain a given charac

2010-02-02 Thread Ted Harding
On 02-Feb-10 15:18:28, Peter Dalgaard wrote:
 mau...@alice.it wrote:
 Unluckily I dela with miRNA files whose name may contain the
 character *.
 Because of the special meaning of * I have to remove it.
 I found out how to make list.files() extract only those file
 names which contain a *
 Namely:
 # list.files(pattern=\\*) 
 
 Now I have to process all files whose name does NOT contain the
 character *.
 I cannot have list.files() extract all files  whose name does NOT
 match pattern=\\*
 I tried using ^ in such a pattern but nothing is returned.
 Any suggestion is welcome.
 
 That'll be something like pattern=^[^*]*$ (untested, I don't think I
 have any filenames with * inside...)
 
 Alternatively, you might try
 
 allfiles - list.files()
 withstar - allfiles[grepl(\\*, allfiles)]
 nostar - allfiles[!grepl(\\*, allfiles)]

Peter's first suggestion works. As often with regeular expressions,
[...] is your friend!

I have created dummy files abcde  pq*st  uvwxyz, and then

  list.files()
  # [1] abcde  pq*st  uvwxyz
  list.files(pattern=[*])
  # [1] pq*st
  list.files(pattern=^[^*]*$)
  # [1] abcde  uvwxyz

Ted.


E-Mail: (Ted Harding) ted.hard...@manchester.ac.uk
Fax-to-email: +44 (0)870 094 0861
Date: 02-Feb-10   Time: 15:41:53
-- XFMail --

__
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] Suppressing scientific notation on plot axis tick labels

2010-02-02 Thread Dimitri Shvorob

options(scipen = 50, digits = 5) 
x  = c(1e7, 2e7) 
barplot(x) 

Still scientific...
-- 
View this message in context: 
http://n4.nabble.com/Suppressing-scientific-notation-on-plot-axis-tick-labels-tp1459697p1459828.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.


[R] R assistance

2010-02-02 Thread dragomir nedeltchev
Dear Madam/Sir,

I read carefully The R Installation and Administration paper. I downloaded 
Rtools11.exe and I run it. As a result there is a directory R on my PC.

Could you please tell me what should I do next in order to run R?

Thank you in advance.

BR
Dragomir Nedeltchev



  
[[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] hiding/protecting utility functions in .Rprofile

2010-02-02 Thread Chris Campbell
On Mon, Feb 1, 2010 at 13:19, Michael Friendly frien...@yorku.ca wrote:
 [Env: WinXp, R 2.9.2]
 In my .Rprofile, I define a number of utility functions I'd like to have
 available in my R session, but don't want them
 to be *normally* listed by ls(), or more importantly, saved if I save my
 session variables/functions.

 How can I do this?

 --
 Michael Friendly     Email: friendly AT yorku DOT ca Professor, Psychology
 Dept.
 York University      Voice: 416 736-5115 x66249 Fax: 416 736-5814
 4700 Keele Street    http://www.math.yorku.ca/SCS/friendly.html
 Toronto, ONT  M3J 1P3 CANADA

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



My strategy for loading my own functions at startup is to keep my
functions in a separate file (not .Rprofile) that I source into its
own environment via .Rprofile.

My .Rprofile looks like this:
###
.diag - new.env()
sys.source( /path/to/sourcefile/functions_to_load.R, envir = .diag )
attach( .diag )
###

I can't claim credit for this; I put it together from other posts on
this mailing list, but I don't remember the source now.  And I cannot
speak to whether this is the best way, but it works fine for me.

Hope that helps.

__
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] 3D plot of following data

2010-02-02 Thread walter.djuric
a link to the 3D plot data files 

http://members.chello.at/gwd

the files are NG_contracts and NG_values

--
mfg
WD

__
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] R assistance

2010-02-02 Thread stephen sefick
Download the R installer from CRAN, and run that.  A desktop icon
should pop up, and you should be set.

Stephen

On Tue, Feb 2, 2010 at 8:16 AM, dragomir nedeltchev
dnedelche...@yahoo.com wrote:
 Dear Madam/Sir,

 I read carefully The R Installation and Administration paper. I downloaded 
 Rtools11.exe and I run it. As a result there is a directory R on my PC.

 Could you please tell me what should I do next in order to run R?

 Thank you in advance.

 BR
 Dragomir Nedeltchev




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




-- 
Stephen Sefick

Let's not spend our time and resources thinking about things that are
so little or so large that all they really do for us is puff us up and
make us feel like gods.  We are mammals, and have not exhausted the
annoying little problems of being mammals.

-K. Mullis

__
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] Suppressing scientific notation on plot axis tick labels

2010-02-02 Thread Meyners, Michael, LAUSANNE, AppliedMathematics
Strange, the following works reproducibly on my machine (Windows 2000
Pro):

options(scipen = 50, digits = 5)
x  = c(1e7, 2e7)
?barplot
barplot(x) 

while I also get scientific with your code. After I called ?barplot
once, I'm incapable of getting the scientific notation again, though...
But I admit that I am outdated, I still run 2.8.1 (but not for long...)

Michael


 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Dimitri Shvorob
 Sent: Dienstag, 2. Februar 2010 12:59
 To: r-help@r-project.org
 Subject: Re: [R] Suppressing scientific notation on plot axis 
 tick labels
 
 
 options(scipen = 50, digits = 5)
 x  = c(1e7, 2e7)
 barplot(x) 
 
 Still scientific...
 --
 View this message in context: 
 http://n4.nabble.com/Suppressing-scientific-notation-on-plot-a
xis-tick-labels-tp1459697p1459828.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.
 

__
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] Odp: Finding the difference between two vectors

2010-02-02 Thread Petr PIKAL
Hi

Option one

vec1-sample(letters[1:10])
vec2-vec1[-5]
vec2-c(vec2,NA)
# missing position
mis-which(!(vec1 %in% vec2))

 c(vec2[1:(mis-1)], NA,vec2[mis:((length(vec2)-1))])
 [1] f e g d NA  j c i b h

gives you desired vector. For two or more values missing it shall be 
rephrased probably by rle

Option two

mis-which(!(vec1 %in% vec2))
vec2 - vec1
vec2 [mis] -NA

Which could be used in case of several values missing.

But I wonder what you want to achieve. It seems to me like you want to do 
something for which merge can be used.

See ?merge

Regards
Petr

 

r-help-boun...@r-project.org napsal dne 02.02.2010 16:34:23:

 
 Hello everyone,
 I have two vectors having only one element different:
vector1 vector2 
 vector1
 
TWC TWC  
 TWC
VFC  TWX  
 NA 
   VIA/B VFC  
 VFC
   WHR VIA/B  
 VIA/B
WPO WHR   -WHR
WYN WPO  
 WPO
WYNN  WYN  
 WYN
YUMWYNN  
 WYNN
NA   YUM  
 YUM
 In that case, in the first vector, the value twx is missing . What I 
want to
 do is doing the following avoiding loop:
 putting the NA row in front of the TWX row as this would be the row 
where
 the value is missing. I don't know if there is any function doing this. 
I
 thought about using a which() function to retrieve all the missing 
elements
 index ( twx, 1 here) and insert them in the right index in the first 
vector
 but how can I insert in a vector, is there an appropriated function? 
thank
 you
 
 -
 Anna Lippel
 -- 
 View this message in context: 
http://n4.nabble.com/Finding-the-difference-
 between-two-vectors-tp1460020p1460020.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.

__
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] Plot - specification for grid of x axis

2010-02-02 Thread Greg Snow
When you create your plot us the argument xaxt='n'.  That will suppress the 
default axis labels and tick marks.  Then use the axis function which lets you 
specify exactly where you want the tick marks and exactly what you want the 
labels to be.  You can also specify tck=1 as an argument if you want grid lines 
(see ?par for details).

Hope this helps,

-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.s...@imail.org
801.408.8111


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of Trafim Vanishek
 Sent: Tuesday, February 02, 2010 8:12 AM
 To: r-help@r-project.org
 Subject: [R] Plot - specification for grid of x axis
 
 Dear all,
 
 I have a simple question for which I cannot find the answer.
 
 I need to make an easy plot, but for the x axis I need to be able to
 specify
 by myself the division of x axis from x[,1] either every single
 observation,
 or every 5th, or 10th or 20th
 
 x - matrix(data=NA, nrow=100, ncol=2)
 x[,1]-seq(1,100,1)
 x[,2]-rnorm(100)
 
 Thanks a lot 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.


[R] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread anna

Hi, I have a data frame datas with half of the columns with the same name
A. I want to delete all those columns from the data frame so here is what
I did:
datas$A - NULL
The problem is that it deleted only one column, I would have to do it as
many times as there are A columns. Is there a way to do it in one time?
thank you

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Deleting-many-columns-of-a-data-frame-with-the-same-name-in-a-row-tp1460078p1460078.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] create an object in a loop (v3)

2010-02-02 Thread Ivan Calandra

Hi David,

Thanks for your answer.
But I don't really see how I can extend it with my real data.
The thing is that I have more than 3 names and 1 value for each name. 
Moreover, each is different from one run to another. That is why I was 
trying with a modification of names(). Also to be noted is that I 
simplified the name in assign(); I actually have 2 other variables 
that will be pasted to create the name.


Here is my code (I kept only what is important for that part):

library(WRS)
seq.num - seq(7,10,1)#column (variable) indexes to be used as 
numerical variables


# fac2list() separates the data from file[,k] into groups from levels in 
file[3] and store into list mode.

for(i in 1:length(seq.num)) {
 k - seq.num[i]
 name.num - names(file)[k]
 assign(paste(names(file)[3], name.num, sep=_), fac2list(file[,k], 
file[3]))
 names(paste(names(file)[3], name.num, sep=_)) - 
levels(factor(file[[3]]))  #that line doesn't work, but I would like 
something in this direction

}


Thanks in advance for your help.
Regards,
Ivan



Le 2/1/2010 18:47, David Winsemius a écrit :


On Feb 1, 2010, at 12:33 PM, Ivan Calandra wrote:


I have a follow-up question:

I use assign() to store some value in my paste()-created object as 
suggested:

for (i in 1:3) {
assign(paste(object, i, sep=), c(a, b, c))
}

Then I would like to change the names of the elements of that object 
within the loop. Since it is all in a loop, I cannot give the name of 
the object manually by doing something like: names(object1) - 
c(tooth, bone, species).
The only thing I can give to names() is paste(object, i, sep=), 
which doesn't work.


Any idea of how to do it?


 for (i in paste(object, 1:3, sep=)) {
+ assign(i, c(tooth=a, bone=b, species=c) )
+ }
 object1
  toothbone species
a b c



Thanks in advance
Ivan


Le 2/1/2010 17:14, David Winsemius a écrit :
Upon reading it yesterday, it appeared as it would have required 
some serious testing and there was no data on which to do any work.  
You were clearly not taking the time to isolate the problem and 
construct a dataset. But who knows? When you say What I want to do 
is. ... ,I would like the name of the list to be created in the loop 
too, maybe all you needed was to be pointed to was:


?assign

But if that were the case, then you lost most of your audience along 
the way with a bunch of unneeded and obscure code.




David Winsemius, MD
Heritage Laboratories
West Hartford, CT




__
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] using rbind in a for loop

2010-02-02 Thread Steve Lianoglou
Hi,

On Mon, Feb 1, 2010 at 11:16 PM, Eunjung Kim eunjung.haw...@gmail.com wrote:
 *Dear R users,
 *I'm facing a trivial problem but I cannot solve it.
 My question is:
 I want to make data set like this.

 i_lon1 i_lat1
 i_lon2 i_lat2
 i_lon3 i_lat3
 i_lon4 i_lat4

 i+1_lon1 i+1_lat1
 i+1_lon2 i+1_lat2
 i+1_lon3 i+1_lat3
 i+1_lon4 i+1_lat4

 i+2_lon1 i+2_lat1
 i+2_lon2 i+2_lat2
 i+2_lon3 i+2_lat3
 i+2_lon4 i+2_lat4
 .
 .
 .

 i+5_lon1 i+5_lat1
 i+5_lon2 i+5_lat2
 i+5_lon3 i+5_lat3
 i+5_lon4 i+5_lat4

I'd like to help, but I have no idea what you have listed above is
supposed to be.

Can you try to give a better example/explanation of what you want?
Are you trying to make one big matrix?
5 different matrices?

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread anna

This is what I just found now but I guess there is a simpler way:

datas[which(names(datas)==A)]-list(rep(NULL,length(which(names(datas)==A
but it worked

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Deleting-many-columns-of-a-data-frame-with-the-same-name-in-a-row-tp1460078p1460091.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] character variables in substitute()

2010-02-02 Thread dkStevens

This is an interesting approach but it doesn't quite get what I want. The
sample below is what I'm looking for where Eik's Title is compared with the
text line within the plot. My text line was produced by the explicit

  text(0.6,1.2,expression(R *'= 13.35, ' *P[m] *'= 2.531, ' *alpha[r] *'=
0.007187'),pos=4)

and the title was produced by

 
expr-bquote(italic(.(pNames[1]))==.(vparams[1])~,~.((pNames[2]))==.(vparams[2]))
  plot(1,1,main=expr)

in which pNames is a vector of character c(R,P[m],...) and vparams is a
vector of characters representing the values with the # of digits limited to
4. What I'm struggling with is to get the pNames recognized as objects
similar to those in the expression above, but using variables rather than
explicitly.

In addition, is is to all go into a function to build the expression for
varying numbers of elements (e.g. maybe just R = or P[m] =, both, or even
more. The return from this function would be the expr that goes into a
text(... command or,as Eik used, a main= plot parameter.

http://n4.nabble.com/file/n1460088/help.png 


-- 
View this message in context: 
http://n4.nabble.com/character-variables-in-substitute-tp1459566p1460088.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.


Re: [R] subset function unexpected behavior

2010-02-02 Thread David Katz

Thanks, that helps! Subset creates a new context where a name clash can
occur. So if I don't want to check for that possibility, I should use a
special kind of index like .sch, or avoid subset:

for(sch in school.list){
  print(sch)
  print(input.data[input.data[,school.var] == sch,])}

which works no matter what variable names I use. That seems like a
reasonable requirement for good code.

(Checking for a name clash would be at least theoretically needed since
school.var is a parameter that can be any character name.)

Although subset conveniently avoids extra typing in many cases (not here),
this suggests to me that it's not ideal for code that can be used in a
variety of contexts. Note that unlike attach, subset does not issue a
warning! 

-

Hi: 

Try this for your second loop instead: 

for(s in school.list){ 
  print(s) 
  print(subset(input.data, sch == s)) 
 } 
[1] 1 
  sch pop 
1   1 100 
2   1 200 
[1] 2 
  sch pop 
3   2 300 
4   2 400 

Don't confound the 'sch' variable in your data frame with the 
index in your loop :) 

HTH, 
Dennis 

On Mon, Feb 1, 2010 at 8:17 PM, David Katz [hidden email]wrote: 
- Hide quoted text -

 
 I was surprised to see this unexpected behavior of subset in a for loop. I 
 looked in subset.data.frame and it seemed to me that both versions should 
 work, since the subset call should be evaluated in the global environment
 - 
 but perhaps I don't understand environments well enough. Can someone 
 enlighten me? In any case, this is a bit of a gotcha for naive users of 
 subset. 
 
 input.data - 
  data.frame(sch=c(1,1,2,2), 
 pop=c(100,200,300,400)) 
 
 school.var - sch 
 
 school.list - 1:2 
 
 for(sch in school.list){ 
  print(sch) 
  #do this before subset!: 
  right.sch.p - 
input.data[,school.var] == sch 
  print(  subset(input.data,right.sch.p)) #this is what I expected 
 } 
 
 ## [1] 1 
 ##   sch pop 
 ## 1   1 100 
 ## 2   1 200 
 ## [1] 2 
 ##   sch pop 
 ## 3   2 300 
 ## 4   2 400 
 
 
 for(sch in school.list){ 
  print(sch) 
  print(subset(input.data,input.data[,school.var] == sch)) #note - compact 
 version fails! 
 } 
 
 ## [1] 1 
 ##   sch pop 
 ## 1   1 100 
 ## 2   1 200 
 ## 3   2 300 
 ## 4   2 400 
 ## [1] 2 
 ##   sch pop 
 ## 1   1 100 
 ## 2   1 200 
 ## 3   2 300 
 ## 4   2 400 
 

-- 
View this message in context: 
http://n4.nabble.com/subset-function-unexpected-behavior-tp1459535p1460057.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] Plot - specification for grid of x axis

2010-02-02 Thread Ally


Have a look at ?par and check out the 'xaxp' parameter

par(mfrow=c(1,2))
plot(x[,2] ~ x[,1], xaxp=c(0,100,5))
plot(x[,2] ~ x[,1], xaxp=c(0,100,10), cex.axis=0.5)
-- 
View this message in context: 
http://n4.nabble.com/Plot-specification-for-grid-of-x-axis-tp1460005p1460083.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] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Gabor Grothendieck
Try:

newdf - datas[names(datas) != A]

On Tue, Feb 2, 2010 at 11:47 AM, anna lippelann...@hotmail.com wrote:

 This is what I just found now but I guess there is a simpler way:

 datas[which(names(datas)==A)]-list(rep(NULL,length(which(names(datas)==A
 but it worked

 -
 Anna Lippel
 --
 View this message in context: 
 http://n4.nabble.com/Deleting-many-columns-of-a-data-frame-with-the-same-name-in-a-row-tp1460078p1460091.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.


__
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] character variables in substitute()

2010-02-02 Thread Gabor Grothendieck
Try this:

leg - function(pNames, vparams) parse(text = paste(pNames, vparams,
sep = ==))
plot(0, main = leg(Sigma, 3.2))
legend(topleft, legend = leg(c(alpha[beta], delta), 1:2))


On Tue, Feb 2, 2010 at 11:44 AM, dkStevens david.stev...@usu.edu wrote:

 This is an interesting approach but it doesn't quite get what I want. The
 sample below is what I'm looking for where Eik's Title is compared with the
 text line within the plot. My text line was produced by the explicit

  text(0.6,1.2,expression(R *'= 13.35, ' *P[m] *'= 2.531, ' *alpha[r] *'=
 0.007187'),pos=4)

 and the title was produced by


 expr-bquote(italic(.(pNames[1]))==.(vparams[1])~,~.((pNames[2]))==.(vparams[2]))
  plot(1,1,main=expr)

 in which pNames is a vector of character c(R,P[m],...) and vparams is a
 vector of characters representing the values with the # of digits limited to
 4. What I'm struggling with is to get the pNames recognized as objects
 similar to those in the expression above, but using variables rather than
 explicitly.

 In addition, is is to all go into a function to build the expression for
 varying numbers of elements (e.g. maybe just R = or P[m] =, both, or even
 more. The return from this function would be the expr that goes into a
 text(... command or,as Eik used, a main= plot parameter.

 http://n4.nabble.com/file/n1460088/help.png


 --
 View this message in context: 
 http://n4.nabble.com/character-variables-in-substitute-tp1459566p1460088.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] Error with toString

2010-02-02 Thread anna

Romain, to keep it simple, I reproduced the example that you can find in the
toString function help and I still got the same error:
 x - c(a, b, aaa)
 toString(x)
Error in toString(x) : could not find function .jcall



-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Error-with-toString-tp1290327p1460119.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] barplot y axis too short

2010-02-02 Thread Jack Siegrist

Thanks for the replies. 

Apparently you cannot adjust the extension factor used by yaxs (which is set
at 4%), so what I did is 
wrote a function (barplotCovered) to get y-axis limits based on the range of
the data and a user-defined axis expansion factor (axExFact).

I included an example below in case someone else has this problem.

# example data
data - c(.10, -.15, .52, .11)

# calculate a maximum and minimum for the y-scale:
# takes the biggest datum: max(data)
# then makes a buffer around it: max(data)*1.1
# then rounds that inflated number to one significant digit:
signif(max(data)*1.1, digits=1)
# then takes the max of that or 0 to allow for positive and negative numbers
axExFact -1.1
ymax - max(c(0, signif(max(data)*axExFact, digits=1)))
ymin - min(c(0, signif(min(data)*axExFact, digits=1)))

# here is the plot
barplot(data, ylim=c(ymin, ymax))

# another example
data2 - c(10, -15, 52, 11)
ymax2 - max(c(0, signif(max(data2)*1.1, digits=1)))
ymin2 - min(c(0, signif(min(data2)*1.1, digits=1)))
barplot(data2, ylim=c(ymin2, ymax2))

# here it is as a function
barplotCovered - function(data, axExFact, ...){
ymax - max(c(0, signif(max(data)*axExFact, digits=1)))
ymin - min(c(0, signif(min(data)*axExFact, digits=1)))
barplot(data, ylim=c(ymin, ymax), ...)
}

# example using the function
barplotCovered(data, axExFact=1.1, names.arg=c(a, b, c, d))

-
Jack Siegrist
Graduate Program in Ecology  Evolution, and Department of Ecology,
Evolution,  Natural Resources,
Rutgers University, New Brunswick, NJ 08901
Jack Siegrist wrote:
 
 
 
 
 The function barplot automatically creates a y-axis that doesn't
 necessarily cover the range of y-values to be plotted. I know how to
 manually create my own y-axis so that it does cover the range, but I was
 wondering if there is some parameter to change so that the scale of the
 y-axis is automatically taller than the tallest bar.
 
 I thought setting xpd=F would do it, since it says that xpd determines
 whether bars will be plotted outside of the plotting region, but it had no
 effect, so I guess it must be dealing with something different.
 
 In the example below, the scale goes to 15 but the second bar goes to 16.
 In this case I would like the scale to go to 20.
 
 Thanks
 
 #example data
 data - c(12, 16)
 
 #none of the following are any different
 barplot(data)
 barplot(data, xpd=T)
 barplot(data, xpd=F)
 

-- 
View this message in context: 
http://n4.nabble.com/barplot-y-axis-too-short-tp1459406p1460108.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] population variance and sample variance

2010-02-02 Thread Peng Yu
On Mon, Oct 19, 2009 at 12:53 PM, Kingsford Jones
kingsfordjo...@gmail.com wrote:
 sum((x-mean(x))^2)/(n)
 [1] 0.4894708
 ((n-1)/n) * var(x)
 [1] 0.4894708

But this is not a built-in function in R to do so, right?

 hth,
 Kingsford

 On Mon, Oct 19, 2009 at 9:30 AM, Peng Yu pengyu...@gmail.com wrote:
 It seems that var() computes sample variance. It is straight forward
 to compute population variance from sample variance. However, I feel
 that it is still convenient to have a function that can compute
 population variance. Is there a population variance function available
 in R?

 $ Rscript var.R
 set.seed(0)
 n = 4
 x = rnorm(n)
 var(x)
 [1] 0.6526278
 sum((x-mean(x))^2)/(n-1)
 [1] 0.6526278


 __
 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] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Phil Spector

Anna -
   You could also look at the problem from the other direction:

  data[,names(datas) != 'A']

- Phil Spector
 Statistical Computing Facility
 Department of Statistics
 UC Berkeley
 spec...@stat.berkeley.edu


On Tue, 2 Feb 2010, anna wrote:



This is what I just found now but I guess there is a simpler way:

datas[which(names(datas)==A)]-list(rep(NULL,length(which(names(datas)==A
but it worked

-
Anna Lippel
--
View this message in context: 
http://n4.nabble.com/Deleting-many-columns-of-a-data-frame-with-the-same-name-in-a-row-tp1460078p1460091.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.



__
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] Error with toString

2010-02-02 Thread jim holtman
What packages are loaded?  On the basic system, it works fine:

 toString(123)
[1] 123
 toString(c('a', 'b', 'zz'))
[1] a, b, zz


On Tue, Feb 2, 2010 at 12:17 PM, anna lippelann...@hotmail.com wrote:

 Romain, to keep it simple, I reproduced the example that you can find in the
 toString function help and I still got the same error:
  x - c(a, b, aaa)
  toString(x)
 Error in toString(x) : could not find function .jcall



 -
 Anna Lippel
 --
 View this message in context: 
 http://n4.nabble.com/Error-with-toString-tp1290327p1460119.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.




-- 
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] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Jeff Laake

Here is one way with an example:

datas=data.frame(x=1:3,A=1:3,A=1:3)
names(datas)=c(x,A,A)
datas
datas=datas[,names(datas)!=A,drop=FALSE]
datas


On 2/2/2010 8:35 AM, anna wrote:

Hi, I have a data frame datas with half of the columns with the same name
A. I want to delete all those columns from the data frame so here is what
I did:
datas$A- NULL
The problem is that it deleted only one column, I would have to do it as
many times as there are A columns. Is there a way to do it in one time?
thank you

-
Anna Lippel



__
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] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Uwe Ligges

datas[ , A != colnames(datas)]

Uwe Ligges

On 02.02.2010 17:35, anna wrote:


Hi, I have a data frame datas with half of the columns with the same name
A. I want to delete all those columns from the data frame so here is what
I did:
datas$A- NULL
The problem is that it deleted only one column, I would have to do it as
many times as there are A columns. Is there a way to do it in one time?
thank you

-
Anna Lippel


__
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] subset function unexpected behavior

2010-02-02 Thread Thomas Lumley

On Tue, 2 Feb 2010, David Katz wrote:



Thanks, that helps! Subset creates a new context where a name clash can
occur. So if I don't want to check for that possibility, I should use a
special kind of index like .sch, or avoid subset:

for(sch in school.list){
 print(sch)
 print(input.data[input.data[,school.var] == sch,])}

which works no matter what variable names I use. That seems like a
reasonable requirement for good code.

(Checking for a name clash would be at least theoretically needed since
school.var is a parameter that can be any character name.)

Although subset conveniently avoids extra typing in many cases (not here),
this suggests to me that it's not ideal for code that can be used in a
variety of contexts. Note that unlike attach, subset does not issue a
warning!


attach() doesn't issue a warning for this situation,  it warns when a variable 
in the data set *fails to* mask one in the global environment.  subset() can't 
fail to mask variables further up the search path, so it doesn't ever warn.

 -thomas

Thomas Lumley   Assoc. Professor, Biostatistics
tlum...@u.washington.eduUniversity of Washington, Seattle

__
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] Doubt about cluster analysis

2010-02-02 Thread Francisco Javier Santos Alamillos
Dear R community,

I'm a beginner with Cluster Analysis. I would like to know if there is a
criterion to select the best set of clusters to do this analysis.

Thanks in advance,

[[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] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Steve Lianoglou
Hi,

On Tue, Feb 2, 2010 at 11:47 AM, anna lippelann...@hotmail.com wrote:

 This is what I just found now but I guess there is a simpler way:

 datas[which(names(datas)==A)]-list(rep(NULL,length(which(names(datas)==A
 but it worked

For what it's worth, you could also have done:

clean - datas[,-which(names(datas)==A)]

(note that indexing with a negative vector removes those
rows/columns from your object (instead of picking them)).

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] Error with toString

2010-02-02 Thread Peter Ehlers

anna wrote:

Romain, to keep it simple, I reproduced the example that you can find in the
toString function help and I still got the same error:
 x - c(a, b, aaa)
 toString(x)
Error in toString(x) : could not find function .jcall


.jcall() is an rJava function. toString() is a base R
function. I'm guessing that you're doing this as part
of some code that involves rJava. In that case
you will have to provide more details.

The example you cite above works perfectly well for me.

 -Peter Ehlers




-
Anna Lippel


--
Peter Ehlers
University of Calgary

__
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] using rbind in a for loop

2010-02-02 Thread jim holtman
This might give you a hint as to how to do it since I have no idea of
what your data looks like:

lon - lat - matrix(1:100, nrow=5)
output - file('/tempxx.txt', open='w')
for (i in 1:5){
x - cbind(lon[,i], lat[,i])
write.table(x, row.names=FALSE, col.names=FALSE, file=output)
cat('\n', file=output)
}
close(output)


This gives a file like:

1 1
2 2
3 3
4 4
5 5

6 6
7 7
8 8
9 9
10 10

11 11
12 12
13 13
14 14
15 15

16 16
17 17
18 18
19 19
20 20

21 21
22 22
23 23
24 24
25 25



On Mon, Feb 1, 2010 at 11:16 PM, Eunjung Kim eunjung.haw...@gmail.com wrote:
 *Dear R users,
 *I'm facing a trivial problem but I cannot solve it.
 My question is:
 I want to make data set like this.

 i_lon1 i_lat1
 i_lon2 i_lat2
 i_lon3 i_lat3
 i_lon4 i_lat4

 i+1_lon1 i+1_lat1
 i+1_lon2 i+1_lat2
 i+1_lon3 i+1_lat3
 i+1_lon4 i+1_lat4

 i+2_lon1 i+2_lat1
 i+2_lon2 i+2_lat2
 i+2_lon3 i+2_lat3
 i+2_lon4 i+2_lat4
 .
 .
 .

 i+5_lon1 i+5_lat1
 i+5_lon2 i+5_lat2
 i+5_lon3 i+5_lat3
 i+5_lon4 i+5_lat4

 My code is
 for (i in 1:5) {
 j - which(!is.na(lat[i,]))
 p - cbind(lon[i,j],lat[i,j])
 cat(c(,p),sep= ,file=data.dat,append=T)}

 and what I got is even not close to what I want: many lines of empty and
 whole bunch of numbers without line change.

 How can I solve this?

 Thanks in advance,
 EJ
 --
 
 Eunjung Kim
 Department of Oceanography
 University of Hawaii at Manoa
 1000 Pope Road
 Honolulu, HI 96822
 United States


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


[R] Doubt about cluster analysis... y más

2010-02-02 Thread Carlos J. Gil Bellosta

Hola, ¿qué tal?

No sé si la conoces, pero te invito a participar en la lista oficial de 
ayuda de R en español:


https://stat.ethz.ch/mailman/listinfo/r-help-es

A través de ella, además de atender dudas de usuarios, tratamos de crear 
una comunidad. De hecho, hace no mucho organizamos las primeras jornadas 
de usuarios de R, etc.


Un cordial saludo,

Carlos J. Gil Bellosta
http://www.datanalytics.com



Francisco Javier Santos Alamillos wrote:

Dear R community,

I'm a beginner with Cluster Analysis. I would like to know if there is a
criterion to select the best set of clusters to do this analysis.

Thanks in advance,

[[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] Error with toString

2010-02-02 Thread anna

Here is the list of the loaded packages:

package:lattice  package:fSeries 
 [5] package:fCalendarpackage:fEcofin 
package:fUtilities   package:MASS
 [9] package:robustbase   package:caTools 
package:PerformanceAnalytics package:xts 
[13] package:xlsReadWrite package:RBloomberg  
package:RUnitpackage:bitops  
[17] package:zoo  package:stats   
package:graphics package:grDevices   
[21] package:datasets package:rcom
package:rscproxy package:utils   
[25] package:methods   package:base

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Error-with-toString-tp1290327p1460190.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] Error with toString

2010-02-02 Thread anna

No I just did it on the R console, I built the vector just before.

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Error-with-toString-tp1290327p1460192.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] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread Henrique Dallazuanna
Try this:

subset(DF, select = setdiff(names(DF), A))


On Tue, Feb 2, 2010 at 2:47 PM, anna lippelann...@hotmail.com wrote:

 This is what I just found now but I guess there is a simpler way:

 datas[which(names(datas)==A)]-list(rep(NULL,length(which(names(datas)==A
 but it worked

 -
 Anna Lippel
 --
 View this message in context: 
 http://n4.nabble.com/Deleting-many-columns-of-a-data-frame-with-the-same-name-in-a-row-tp1460078p1460091.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.


[R] List of object properties

2010-02-02 Thread Philipp Rappold

Dear all,

I have a simple question: How can I retrieve a list with all 
properties of an object?


Example:
If I fit a regression with

model - coxph(Surv()~...)

I know that I can access the coefficients with 
model$coefficients[...] afterwards, but how do I know which other 
variables are available and what are their names?


Thanks and all the best
Philipp

__
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] Deleting many columns of a data frame with the same name ina row

2010-02-02 Thread William Dunlap

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Steve Lianoglou
 Sent: Tuesday, February 02, 2010 9:05 AM
 To: anna
 Cc: r-help@r-project.org
 Subject: Re: [R] Deleting many columns of a data frame with 
 the same name ina row
 
 Hi,
 
 On Tue, Feb 2, 2010 at 11:47 AM, anna 
 lippelann...@hotmail.com wrote:
 
  This is what I just found now but I guess there is a simpler way:
 
  
 datas[which(names(datas)==A)]-list(rep(NULL,length(which(na
mes(datas)==A
  but it worked
 
 For what it's worth, you could also have done:
 
 clean - datas[,-which(names(datas)==A)]
 
 (note that indexing with a negative vector removes those
 rows/columns from your object (instead of picking them)).

I would recommend replacing
  datas[, -which(names(data)==A)]
with   
  datas[, names(data)!=A]
because the former returns a zero-column data.frame if there
are columns of datas named A.  (which(rep(F,n))-integer(0)
and -integer(0) is identical to integer(0), which selects
no elements).  The latter returns the entire data.frame in
the case.

Logical subscripts are your friend.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 

 
 -steve
 
 -- 
 Steve Lianoglou
 Graduate Student: Computational Systems Biology
  | Memorial Sloan-Kettering Cancer Center
  | Weill Medical College of Cornell University
 Contact Info: http://cbio.mskcc.org/~lianos/contact
 
 __
 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] Error with write.table

2010-02-02 Thread jlwoodard

I was trying to save a data frame to an excel file using the following
command:

write.table(myData, file=myData.csv,sep=,, row.names=F)

The command works for some data frames, but for other data frames, I get the
following error:

Error in if (inherits(X[[j]], data.frame)  ncol(xj)  1L) X[[j]] -
as.matrix(X[[j]]) : 
  missing value where TRUE/FALSE needed


Is there something I'm doing wrong in trying to save the data frame to a
.csv file?  

Many thanks in advance! 

John Woodard

-- 
View this message in context: 
http://n4.nabble.com/Error-with-write-table-tp1460198p1460198.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.


[R] Subset and point plot

2010-02-02 Thread Marlin Keith Cox
OK, I need help plotting.  I have column headings of Day, Wgt, Foodin, Rep,
Grp and Tanks.  Rep=c(1,2,3) and Tanks=c(a1,a2,a3,a4,a5,a6,
c1,c2,c3,c4,c5,c6, h1,h2,h3,h4,h5,h6).

I created a subset where I only would like Rep=2, and Tanks=c(a4,c4,h4) and
would like to graph (points) of Wgt and Day.  I would think that I only need
3 colors, but when I run with only 3, only 2 lines show up.  When I add a
4th color (pink in this case), I get the 3rd line.  If I subset for
c(a1,a2,a3), it works using three colors.  Should be simple, but I dont see
it.

rm(list=ls())

daily-subset(raw, subset=Foodin1  Rep==2  Grp==fed  Tanks==a4|
Foodin1  Rep==2  Grp==fed  Tanks==c4|Foodin1  Rep==2  Grp==fed
 Tanks==h4)
attach(daily)
x11()
par(cex=1.4)
plot(Day, Wgt col=c(red,blue,purple,pink)[Tanks])
detach(daily)


-- 
M. Keith Cox, Ph.D.
Alaska NOAA Fisheries, National Marine Fisheries Service
Auke Bay Laboratories
17109 Pt. Lena Loop Rd.
Juneau, AK 99801
keith@noaa.gov
marlink...@gmail.com
U.S. (907) 789-6603

[[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] Retrieve distinct values within a whole data frame

2010-02-02 Thread anna

Hello everyone, 
I am trying to retrieve the list of distinct values within a whole data
frame. I tried to use unique() function but it retrieves the distinct values
within each column or row, I want it for the entire data frame, any idea?

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Retrieve-distinct-values-within-a-whole-data-frame-tp1460205p1460205.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] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread anna

thanks this is actually shorter :)

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Deleting-many-columns-of-a-data-frame-with-the-same-name-in-a-row-tp1460078p1460208.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] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread anna

yes it looks really simpler, thank you!

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Deleting-many-columns-of-a-data-frame-with-the-same-name-in-a-row-tp1460078p1460213.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] Retrieve distinct values within a whole data frame

2010-02-02 Thread Steve Lianoglou
Hi,

On Tue, Feb 2, 2010 at 1:19 PM, anna lippelann...@hotmail.com wrote:

 Hello everyone,
 I am trying to retrieve the list of distinct values within a whole data
 frame. I tried to use unique() function but it retrieves the distinct values
 within each column or row, I want it for the entire data frame, any idea?

Here's one way:

R df - data.frame(a=c(1,2,3,4,3,2), b=c(4,5,6,6,4,3))
R unique(unlist(df))
[1] 1 2 3 4 5 6

I guess funny things might happen when the columns of your data.frame
are of different types, though ...

-steve
-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
 | Memorial Sloan-Kettering Cancer Center
 | Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

__
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] Error with write.table

2010-02-02 Thread Erik Iverson
How about a MINIMAL example of a data.frame that produces the error 
message you see? That will help track down what's going on...


jlwoodard wrote:

I was trying to save a data frame to an excel file using the following
command:

write.table(myData, file=myData.csv,sep=,, row.names=F)

The command works for some data frames, but for other data frames, I get the
following error:

Error in if (inherits(X[[j]], data.frame)  ncol(xj)  1L) X[[j]] -
as.matrix(X[[j]]) : 
  missing value where TRUE/FALSE needed



Is there something I'm doing wrong in trying to save the data frame to a
.csv file?  

Many thanks in advance! 


John Woodard



__
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] Retrieve distinct values within a whole data frame

2010-02-02 Thread anna

ok it worked so the key is unlist() from what I see :working:

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Retrieve-distinct-values-within-a-whole-data-frame-tp1460205p1460217.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] create an object in a loop (v3)

2010-02-02 Thread Chris Campbell
On Tue, Feb 2, 2010 at 11:44, Ivan Calandra
ivan.calan...@uni-hamburg.de wrote:
 Hi David,

 Thanks for your answer.
 But I don't really see how I can extend it with my real data.
 The thing is that I have more than 3 names and 1 value for each name.
 Moreover, each is different from one run to another. That is why I was
 trying with a modification of names(). Also to be noted is that I simplified
 the name in assign(); I actually have 2 other variables that will be
 pasted to create the name.

 Here is my code (I kept only what is important for that part):
 
 library(WRS)
 seq.num - seq(7,10,1)        #column (variable) indexes to be used as
 numerical variables

 # fac2list() separates the data from file[,k] into groups from levels in
 file[3] and store into list mode.
 for(i in 1:length(seq.num)) {
  k - seq.num[i]
  name.num - names(file)[k]
  assign(paste(names(file)[3], name.num, sep=_), fac2list(file[,k],
 file[3]))
  names(paste(names(file)[3], name.num, sep=_)) -
 levels(factor(file[[3]]))  #that line doesn't work, but I would like
 something in this direction
 }
 

Sounds like a job for 'get'.  Try this (untested):

names(get(paste(names(file)[3], name.num, sep=_)))

Good luck


 Thanks in advance for your help.
 Regards,
 Ivan



 Le 2/1/2010 18:47, David Winsemius a écrit :

 On Feb 1, 2010, at 12:33 PM, Ivan Calandra wrote:

 I have a follow-up question:

 I use assign() to store some value in my paste()-created object as
 suggested:
 for (i in 1:3) {
 assign(paste(object, i, sep=), c(a, b, c))
 }

 Then I would like to change the names of the elements of that object
 within the loop. Since it is all in a loop, I cannot give the name of the
 object manually by doing something like: names(object1) - c(tooth,
 bone, species).
 The only thing I can give to names() is paste(object, i, sep=), which
 doesn't work.

 Any idea of how to do it?

  for (i in paste(object, 1:3, sep=)) {
 + assign(i, c(tooth=a, bone=b, species=c) )
 + }
  object1
  tooth    bone species
    a     b     c


 Thanks in advance
 Ivan


 Le 2/1/2010 17:14, David Winsemius a écrit :

 Upon reading it yesterday, it appeared as it would have required some
 serious testing and there was no data on which to do any work.  You were
 clearly not taking the time to isolate the problem and construct a dataset.
 But who knows? When you say What I want to do is. ... ,I would like the
 name of the list to be created in the loop too, maybe all you needed was 
 to
 be pointed to was:

 ?assign

 But if that were the case, then you lost most of your audience along the
 way with a bunch of unneeded and obscure code.


 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT



 __
 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] Error with toString

2010-02-02 Thread Peter Ehlers

Anna,

Try omitting pkg:RBloomberg.
If you really need to use that package, you will have to
install the non-CRAN package RDCOMClient from omegahat.

I still don't see why toString() wouldn't do its job, even
with RBloomberg loaded.

 -Peter Ehlers

anna wrote:

Here is the list of the loaded packages:

package:lattice  package:fSeries 
 [5] package:fCalendarpackage:fEcofin 
package:fUtilities   package:MASS
 [9] package:robustbase   package:caTools 
package:PerformanceAnalytics package:xts 
[13] package:xlsReadWrite package:RBloomberg  
package:RUnitpackage:bitops  
[17] package:zoo  package:stats   
package:graphics package:grDevices   
[21] package:datasets package:rcom
package:rscproxy package:utils   
[25] package:methods   package:base


-
Anna Lippel


--
Peter Ehlers
University of Calgary

__
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] character variables in substitute()

2010-02-02 Thread Dennis Murphy
Hi:

Taking David's and Gabor's contributions, I came up with a function that I
hope
satisfies David's needs:

parText - function(names, pars) {
 p1 - paste(* '= , pars[-length(pars)], , '*, sep = )
 p2 - paste(* '= , pars[length(pars)], ')
 p - c(p1, p2)
 txt - paste(names, p, collapse = )
 parse(text = txt)
}

Tests:
names - c('R', 'P', 'K', 'alpha')
vals - c(13.35, 2.53, 4.06, 0.0072)

# Different length inputs
vars - c('beta', 'K[m]')
pars - c(12, 0.6)

plot(c(0, 2), c(0, 2))
text(0, 1, parText(names, vals), adj = 0)
text(0, 0.5, parText(vars, pars))
title(parText(vars, pars))

Does that work?
Dennis




On Tue, Feb 2, 2010 at 8:44 AM, dkStevens david.stev...@usu.edu wrote:


 This is an interesting approach but it doesn't quite get what I want. The
 sample below is what I'm looking for where Eik's Title is compared with the
 text line within the plot. My text line was produced by the explicit

  text(0.6,1.2,expression(R *'= 13.35, ' *P[m] *'= 2.531, ' *alpha[r] *'=
 0.007187'),pos=4)

 and the title was produced by



 expr-bquote(italic(.(pNames[1]))==.(vparams[1])~,~.((pNames[2]))==.(vparams[2]))
   plot(1,1,main=expr)

 in which pNames is a vector of character c(R,P[m],...) and vparams is a
 vector of characters representing the values with the # of digits limited
 to
 4. What I'm struggling with is to get the pNames recognized as objects
 similar to those in the expression above, but using variables rather than
 explicitly.

 In addition, is is to all go into a function to build the expression for
 varying numbers of elements (e.g. maybe just R = or P[m] =, both, or even
 more. The return from this function would be the expr that goes into a
 text(... command or,as Eik used, a main= plot parameter.

 http://n4.nabble.com/file/n1460088/help.png


 --
 View this message in context:
 http://n4.nabble.com/character-variables-in-substitute-tp1459566p1460088.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.


[[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] merging data frames gives all NAs

2010-02-02 Thread James Rome
On 2/1/2010 5:51 PM, David Winsemius wrote:
I figured this out finally. I really believe that the R help write-ups
are sorely lacking. As soon as I looked at
http://www.statmethods.net/management/merging.html, it was obvious:


Adding Columns

To merge two dataframes (datasets) horizontally, use the *merge*
function. In most cases, you join two dataframes by one or more common
key variables (i.e., an inner join).

|# merge two dataframes by ID
total - merge(dataframeA,dataframeB,by=ID)|

|# merge two dataframes by ID and Country
total - merge(dataframeA,dataframeB,by=c(ID,Country)) |


Adding Rows

To join two dataframes (datasets) vertically, use the* rbind* function.
The two dataframes *must* have the same variables, but they do not have
to be in the same order.

|total - rbind(dataframeA, dataframeB) |

I needed to add rows, and had to use rbind. If the help for merge said
To merge two dataframes (datasets) horizontally I would have known
right away that it was the wrong function to use.

Thanks for the help,
Jim Rome


On Feb 1, 2010, at 5:30 PM, David Winsemius wrote:


 On Feb 1, 2010, at 5:16 PM, James Rome wrote:

 Dear kind R helpers,

 I have a vector of runway names in rwy  (31R, 31L,...  the number
 is user selectable)
 arrgnd is a data frame with data for all flights and all runways,
 with a Runway column.
 I am trying to subset arrgnd into a dat frame for each selected
 runway, and then combine them back together using the following code:

 for (j in 1:nr) {# nr = number of user-selected runways

 Safer would be:

 for (j in seq_along(rwy) {

   ar4rw = arrgnd[arrgnd$Runway==rwy[j],]

 Clearer would be :

ar4rw - subset(arrgnd, Runway= j) # and I think the NA line's
 will also disappear.
 ^ ==  ^


   if (j == 1) {
   arrw = ar4rw
   }
   else {
   arrw = merge(arrw, ar4rw)
   }
 }

 You really should give us something like:

 dput(rwy)
 dput( head(arrgnd, 10) )

 but, the merge step gives me a data frame with all NAs. In addition,
 ar4rw always gets a row with NAs at the start, which I do not
 understand. There are no rows with all NAs in the arrgnd data frame.
  ar4rw[1:2,]  # first time through for 31R
   DateTime   Date month hour minute quarter weekday IATA ICAO
 Flight
 NA NA NANA   NA NA  NA  NA NA NA NA
 529 1/1/09 21:46 2009-01-01 1   21 46  87   5   TA 
 TAI TAI570
   AircraftType   Tail  Arrived   STA Runway FromTo Delay
 NA NA NA NA NA NA NANA
 529 A320 N496TA 21:46:58 22:3031R MSLP /KJFK 0
  Operatordq gw
 NA NA NA NA
 529 TACA INTERNATIONAL AIRLINES 2009-01-01 87  1

  ar4rw[1:2,]   # second time through for 31L
   DateTime   Date month hour minute quarter weekday IATA ICAO
 Flight
 NA NA NANA   NA NA  NA  NA NA NA NA
 552 1/1/09 23:03 2009-01-01 1   23  3  92   5   AA 
 AAL  AAL22
   AircraftType   Tail  Arrived   STA RunwayFromTo Delay 
 Operator
 NA NA NA NA NA NA NANA NA
 552 B762 N329AA 23:03:35 23:1031L LAX  /JFK 0
 AMERICAN AIRLINES
  dq gw
 NA NA NA

 But after the merge, I get all NAs. What am I doing wrong?

 The data layout gets mangled and I cannot tell what rows are being
 matched to what. Use dput to convey an unambiguous, and easily
 replicated example.

 Thanks,
 Jim Rome

 552 2009-01-01 92  1

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

 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT

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

David Winsemius, MD
Heritage Laboratories
West Hartford, CT



[[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] List of object properties

2010-02-02 Thread David Winsemius


On Feb 2, 2010, at 1:08 PM, Philipp Rappold wrote:


Dear all,

I have a simple question: How can I retrieve a list with all  
properties of an object?


Example:
If I fit a regression with

model - coxph(Surv()~...)

I know that I can access the coefficients with model 
$coefficients[...] afterwards, but how do I know which other  
variables are available and what are their names?


?str



Thanks and all the best
Philipp

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] Deleting many columns of a data frame with the same name in a row

2010-02-02 Thread David Winsemius


On Feb 2, 2010, at 12:04 PM, Steve Lianoglou wrote:


Hi,

On Tue, Feb 2, 2010 at 11:47 AM, anna lippelann...@hotmail.com  
wrote:


This is what I just found now but I guess there is a simpler way:

datas[which(names(datas)==A)]- 
list(rep(NULL,length(which(names(datas)==A

but it worked


For what it's worth, you could also have done:

clean - datas[,-which(names(datas)==A)]

(note that indexing with a negative vector removes those
rows/columns from your object (instead of picking them)).


But only with numeric vectors.



-steve

--
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

__
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] Subset and point plot

2010-02-02 Thread Peter Ehlers

I tried your code and a funny thing happened: I got an
error

 object 'Foodin' not found

Hmmm; could you try to post something _reproducible_
(and minimal, please)?

But here are some suggestions:
1. investigate '%in%'
2. put a comma after Wgt in your plot call
3. see what you get from

  c(red,blue,purple,pink)[a4]

4. assuming that 'Tanks' is a factor, see what you get from

  c(red,blue,purple,pink)[Tanks]

 -Peter Ehlers

Marlin Keith Cox wrote:

OK, I need help plotting.  I have column headings of Day, Wgt, Foodin, Rep,
Grp and Tanks.  Rep=c(1,2,3) and Tanks=c(a1,a2,a3,a4,a5,a6,
c1,c2,c3,c4,c5,c6, h1,h2,h3,h4,h5,h6).

I created a subset where I only would like Rep=2, and Tanks=c(a4,c4,h4) and
would like to graph (points) of Wgt and Day.  I would think that I only need
3 colors, but when I run with only 3, only 2 lines show up.  When I add a
4th color (pink in this case), I get the 3rd line.  If I subset for
c(a1,a2,a3), it works using three colors.  Should be simple, but I dont see
it.

rm(list=ls())

daily-subset(raw, subset=Foodin1  Rep==2  Grp==fed  Tanks==a4|
Foodin1  Rep==2  Grp==fed  Tanks==c4|Foodin1  Rep==2  Grp==fed
 Tanks==h4)
attach(daily)
x11()
par(cex=1.4)
plot(Day, Wgt col=c(red,blue,purple,pink)[Tanks])
detach(daily)




--
Peter Ehlers
University of Calgary

__
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] merging data frames gives all NAs

2010-02-02 Thread Erik Iverson



James Rome wrote:

On 2/1/2010 5:51 PM, David Winsemius wrote:
I figured this out finally. I really believe that the R help write-ups
are sorely lacking. 


The help docs are probably not the best way to learn R, but they are 
great for users of the functions.  I have found that after going through 
an introduction book on R or online tutorial (plus experience), that the 
help system in R is really, really good at *documenting the behavior of 
the functions*, which is the point of them.


As another general hint from someone who has learned R slowly over time, 
when something happens that you don't understand on real data, 
construct a minimal example data.frame and try out your code on that. 
Also, learning how to use browser() or the debug package has been very 
useful.


__
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] List of object properties

2010-02-02 Thread Peter Ehlers

Philipp,

Check ?str which displays the structure of R objects.
And do use extractor functions when available:
coef(yourModel) instead of yourModel$coef

 -Peter Ehlers

Philipp Rappold wrote:

Dear all,

I have a simple question: How can I retrieve a list with all properties 
of an object?


Example:
If I fit a regression with

model - coxph(Surv()~...)

I know that I can access the coefficients with model$coefficients[...] 
afterwards, but how do I know which other variables are available and 
what are their names?


Thanks and all the best
Philipp

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




--
Peter Ehlers
University of Calgary

__
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] population variance and sample variance

2010-02-02 Thread Ista Zahn
Probably a simple typo, but just to keep things straight: you want to
divide by n when describing the standard deviation of a sample, and
divide by n-1 when estimating a population standard deviation (your
initial description had it backwards I think).

On Tue, Feb 2, 2010 at 5:25 PM, Peng Yu pengyu...@gmail.com wrote:
 On Mon, Oct 19, 2009 at 12:53 PM, Kingsford Jones
 kingsfordjo...@gmail.com wrote:
 sum((x-mean(x))^2)/(n)
 [1] 0.4894708
 ((n-1)/n) * var(x)
 [1] 0.4894708

 But this is not a built-in function in R to do so, right?

 hth,
 Kingsford

 On Mon, Oct 19, 2009 at 9:30 AM, Peng Yu pengyu...@gmail.com wrote:
 It seems that var() computes sample variance. It is straight forward
 to compute population variance from sample variance. However, I feel
 that it is still convenient to have a function that can compute
 population variance. Is there a population variance function available
 in R?

 $ Rscript var.R
 set.seed(0)
 n = 4
 x = rnorm(n)
 var(x)
 [1] 0.6526278
 sum((x-mean(x))^2)/(n-1)
 [1] 0.6526278


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




-- 
Ista Zahn
Graduate student
University of Rochester
Department of Clinical and Social Psychology
http://yourpsyche.org

__
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] factorial map?

2010-02-02 Thread Sacha Viquerat
hello! i'm dealing with the following: i've collected a factor 
covariable at irregularly placed sampling points along a line with 
spatial informations, i.e.: dataset-c(x-coordinates, y-coordinates, 
level-of-factor)
the factor describes the density of vegetation between 0 (no ground 
cover) and 5 (almost complete cover). id like to produce a map similar 
to the ones the akima package enables me to (function in akima is 
called: interp(x,y,z-value...), then use image(...) on the resulting data).
but: as the akima library works suitable with continuous z-values 
(topography, air pressure, whatever is measured can be described a 
number), my resulting map looks terribly patchy (of course, since the 
levels of the factor cannot be interpolated) and contains no valuable 
information. thus my question: i imagine something like a growing-cells 
mechanism, which lets every sample grow until its borders touch the 
borders of an adjacent sample, resulting in something like a 
honeycomb-structure. that would give me a cellular pattern of my factor 
spread across the map!


__
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] merging data frames gives all NAs

2010-02-02 Thread James Rome
I agree. I have a foot of books on R now, for example the R Book by
Michael Crowly. But so far, Googling the archives of this list has been
the most help. Nonetheless, if I cannot understand the documentation of
a function, then the documentation needs to be updated. For example,
there needs to be a Returns section at the top of every function, so
one can see what type of thing the function returns.

Merge() needs to start with To merge two dataframes (datasets)
horizontally, use the *merge* function. rather than

Merge two data frames by common columns or row names, or do other
versions of database /join/ operations which does not at all say that
it does a horizontal merge if one does not know SQL. I do know SQL, and
it is still not clear to me. And the/ merge/ documentation should then
refer users to/ rbind/ for vertical merges.

I hope that someone on the list can take actually change this file for
the benefit of others.

Thanks,
Jim


On 2/2/2010 2:00 PM, Erik Iverson wrote:

James Rome wrote:
 On 2/1/2010 5:51 PM, David Winsemius wrote:
 I figured this out finally. I really believe that the R help write-ups
 are sorely lacking. 

The help docs are probably not the best way to learn R, but they are
great for users of the functions.  I have found that after going through
an introduction book on R or online tutorial (plus experience), that the
help system in R is really, really good at *documenting the behavior of
the functions*, which is the point of them.

As another general hint from someone who has learned R slowly over time,
when something happens that you don't understand on real data,
construct a minimal example data.frame and try out your code on that.
Also, learning how to use browser() or the debug package has been very
useful.


[[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] merging data frames gives all NAs

2010-02-02 Thread David Winsemius
Yeah, sometimes the vocabulary we bring to a task does not match up  
(or merge properly) with the vocabulary that the developers use. In  
this case the merge operation is one that has a precise meaning in  
database lingo, which apparently you do not have background in.  My  
experience in trying to append objects ran into similar frustrations  
early in my R endeavors. For the life of me, I could not find any  
instances of append in the index of the references I was using.


I am glad that you found that material helpful, but I think its use of  
the terms join or merge  are incorrect in a database framework as  
well, so I do not think it could be used as an unambiguous guide. Your  
use of combine was likewise ambiguous. In composing questions to R- 
help, it is advised that you post a small example and illustrate what  
you want to see as a result.


--
David.



On Feb 2, 2010, at 1:47 PM, James Rome wrote:


On 2/1/2010 5:51 PM, David Winsemius wrote:
I figured this out finally. I really believe that the R help write- 
ups are sorely lacking.


You should ponder whether you actually know enough to criticize the  
help page when it describes the merge function as performing database  
join operations. My guess is that you don't. The help page are not to  
be designed to teach basic computer programming concepts.




As soon as I looked at http://www.statmethods.net/management/merging.html 
, it was obvious:

Adding Columns
To merge two dataframes (datasets) horizontally, use the merge  
function. In most cases, you join two dataframes by one or more  
common key variables (i.e., an inner join).


# merge two dataframes by ID
total - merge(dataframeA,dataframeB,by=ID)

# merge two dataframes by ID and Country
total - merge(dataframeA,dataframeB,by=c(ID,Country))

Adding Rows
To join two dataframes (datasets) vertically, use the rbind  
function. The two dataframes must have the same variables, but they  
do not have to be in the same order.


total - rbind(dataframeA, dataframeB)

I needed to add rows, and had to use rbind. If the help for merge  
said To merge two dataframes (datasets) horizontally I would have  
known right away that it was the wrong function to use.


Thanks for the help,
Jim Rome


On Feb 1, 2010, at 5:30 PM, David Winsemius wrote:



On Feb 1, 2010, at 5:16 PM, James Rome wrote:


Dear kind R helpers,

I have a vector of runway names in rwy  (31R, 31L,...  the  
number is user selectable)
arrgnd is a data frame with data for all flights and all runways,  
with a Runway column.
I am trying to subset arrgnd into a dat frame for each selected  
runway, and then combine them back together using the following  
code:


for (j in 1:nr) {# nr = number of user-selected runways


Safer would be:

for (j in seq_along(rwy) {


  ar4rw = arrgnd[arrgnd$Runway==rwy[j],]


Clearer would be :

   ar4rw - subset(arrgnd, Runway= j) # and I think the NA  
line's will also disappear.

 ^ ==  ^




  if (j == 1) {
  arrw = ar4rw
  }
  else {
  arrw = merge(arrw, ar4rw)
  }
}


You really should give us something like:

dput(rwy)
dput( head(arrgnd, 10) )


but, the merge step gives me a data frame with all NAs. In  
addition, ar4rw always gets a row with NAs at the start, which I  
do not understand. There are no rows with all NAs in the arrgnd  
data frame.

 ar4rw[1:2,]  # first time through for 31R
  DateTime   Date month hour minute quarter weekday IATA  
ICAO Flight

NA NA NANA   NA NA  NA  NA NA NA NA
529 1/1/09 21:46 2009-01-01 1   21 46  87   5
TA  TAI TAI570

  AircraftType   Tail  Arrived   STA Runway FromTo Delay
NA NA NA NA NA NA NANA
529 A320 N496TA 21:46:58 22:3031R MSLP /KJFK 0
 Operatordq gw
NA NA NA NA
529 TACA INTERNATIONAL AIRLINES 2009-01-01 87  1

 ar4rw[1:2,]   # second time through for 31L
  DateTime   Date month hour minute quarter weekday IATA  
ICAO Flight

NA NA NANA   NA NA  NA  NA NA NA NA
552 1/1/09 23:03 2009-01-01 1   23  3  92   5
AA  AAL  AAL22
  AircraftType   Tail  Arrived   STA RunwayFromTo  
Delay  Operator

NA NA NA NA NA NA NANA NA
552 B762 N329AA 23:03:35 23:1031L LAX  /JFK 0  
AMERICAN AIRLINES

 dq gw
NA NA NA

But after the merge, I get all NAs. What am I doing wrong?


The data layout gets mangled and I cannot tell what rows are being  
matched to what. Use dput to convey an unambiguous, and easily  
replicated example.


Thanks,
Jim Rome

552 2009-01-01 92  1

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT


[R] mysterious extra spaces appearing in expression paste

2010-02-02 Thread George Locke
Hi,

i'm trying to put a legend on some figures and they're coming out a
bit wonky.  here's an example:

a - c(1:10)
par(mfrow=c(2,1))
plot(a,type=s,lwd=3)
leg - c(expression(paste(data1 (,rho,=1))),
expression(paste(data2 (,rho,=0.0
legend(bottomright,legend=leg,col=c(1,2),lwd=3)
plot(a,type=s,lwd=3)
leg - c(expression(paste(data1 \n(,rho,=1))),
expression(paste(data2 \n(,rho,=0.0
legend(bottomright,legend=leg,col=c(1,2),lwd=3, y.intersp = 2.0,adj=c(0,1.5))

the problem is that lots of extra space appears between the open
parenthesis and the rho.

what can be done?  (i'm running  version 2.10.1 (2009-12-14) on fedora 12)

Thanks!

George Locke

__
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] StructTS standard errors

2010-02-02 Thread MY

I just did a search on StructTS on the same topic and ended up here.  Did
this issue ever get resolved here or elsewhere?


Regards,
Myron
-- 
View this message in context: 
http://n4.nabble.com/StructTS-standard-errors-tp966079p1460216.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] Import fixed-format ascii file with mixed record types

2010-02-02 Thread trece por ciento
Thanks Jim,
As I know nothing about Perl (is it really necessary?), I think that I will try 
with David's approach.
What I want to do is to for a pseudo-panel with my survey data (that is 
collected periodically), and process it with the survey package. The resulting 
data set will be big (around 3.2 million records and 400 MBytes).
Hug

--- On Mon, 2/1/10, Jim Holtman jholt...@gmail.com wrote:

 From: Jim Holtman jholt...@gmail.com
 Subject: Re: [R] Import fixed-format ascii file with mixed record types
 To: trece por ciento el13porcie...@yahoo.com
 Cc: David Winsemius dwinsem...@comcast.net, r-help@r-project.org 
 r-help@r-project.org
 Date: Monday, February 1, 2010, 4:43 PM
 you probably need to split your file
 into several files according to the format. you can use
 something like perl or do it within R by doing readline and
 then separating the lines. you can use grep, split and
 textConnection to do most of the work.
 
 What is the problem you are trying to solve?
 
 Sent from my iPhone.
 
 On Feb 1, 2010, at 14:33, trece por ciento el13porcie...@yahoo.com
 wrote:
 
  Thanks David, but can read.fwf cope with different
 record types?
  For example, if recordtype is the 4th character, I
 could have:
  
  011125678 --- This is record Type 1
  011136779 --- This is record Type 1
  011124943 --- This is record Type 1
  011286711 --- This is record Type 2
  011234872 --- This is record Type 2
  011135628 --- This is record Type 1
  
  So, how can I tell read.fwf to take the correct type
 into account?
  Thanks again,
  Hug
  
  --- On Mon, 2/1/10, David Winsemius dwinsem...@comcast.net
 wrote:
  
  From: David Winsemius dwinsem...@comcast.net
  Subject: Re: [R] Import fixed-format ascii file with
 mixed record types
  To: trece por ciento el13porcie...@yahoo.com
  Cc: r-help@r-project.org
  Date: Monday, February 1, 2010, 12:01 PM
  
  
  On Feb 1, 2010, at 11:40 AM, trece por ciento wrote:
  
  I need to import several ascii files in fixed
 format with two different record types. The data comes from
 European Labor Force Surveys, wich is a household survey.
 The first record type is for people over 16 years, and the
 second much sorter is for people aged 15 or less (this
 record has a filler with several blanks to get the same
 record length).
  The files tipically have 16 records, with 176
 characters per record, the data is numeric, corresponding to
 102 variables, mostly integers (seven variables have two
 decimals). My opertating system is Windows XP.
  My questions:
  1. Wich do you think is the best way to import the
 files into R?
  
  
  ?read.fwf
  
  2. Could you give me any references or examples?
  
  There are examples in the help page.
  
  Thanking you in advance,
  Hug
  
  
  
  
      [[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.
  
  David Winsemius, MD
  Heritage Laboratories
  West Hartford, CT
  
  
  
  
  
  
  __
  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] Import fixed-format ascii file with mixed record types

2010-02-02 Thread trece por ciento
Thanks again, David
I think that this could work.
Final questions:
1. I have read that read.fwt could be slow for big tables (my tables have 
aprox. 16 records, with 176 characters of recordlenght, almost 28MBytes). 
Could that be a problem?
2. If using read.fwt is not a problem, wouldn't be better to read all the 
records by read.fwt into a dataframe with the Type 1 structure, and then 
process the Type 2 records in the dataframe adding new fields for these records 
(NULL valued for Type 1)?
Hug

--- On Mon, 2/1/10, David Winsemius dwinsem...@comcast.net wrote:

 From: David Winsemius dwinsem...@comcast.net
 Subject: Re: [R] Import fixed-format ascii file with mixed record types
 To: trece por ciento el13porcie...@yahoo.com
 Cc: r-help@r-project.org
 Date: Monday, February 1, 2010, 2:23 PM
 
 On Feb 1, 2010, at 2:33 PM, trece por ciento wrote:
 
  Thanks David, but can read.fwf cope with different
 record types?
  For example, if recordtype is the 4th character, I
 could have:
  
  011125678 --- This is record Type 1
  011136779 --- This is record Type 1
  011124943 --- This is record Type 1
  011286711 --- This is record Type 2
  011234872 --- This is record Type 2
  011135628 --- This is record Type 1
  
  So, how can I tell read.fwf to take the correct type
 into account?
 
 You may need to separate the line-types first. If the
 numbers of lines are not too large then this would exemplify
 a strategy:
 
  txt - 011125678
 + 011136779
 + 011124943
 + 011286711
 + 011234872
 + 011135628
 
  substr(readLines(textConnection(txt)), 4,4)
 [1] 1 1 1 2 2 1
  file1 -
 readLines(textConnection(txt))[substr(readLines(textConnection(txt)),
 4,4) == 1]
  file2 -
 readLines(textConnection(txt))[substr(readLines(textConnection(txt)),
 4,4) == 2]
  file1
 [1] 011125678 011136779 011124943 011135628
  file2
 [1] 011286711 011234872
 
 Then these text objects could be processed with
 read.fwf(textConnection(file1) and the same for file2.
 
 --David.
 
  Thanks again,
  Hug
  
  --- On Mon, 2/1/10, David Winsemius dwinsem...@comcast.net
 wrote:
  
  From: David Winsemius dwinsem...@comcast.net
  Subject: Re: [R] Import fixed-format ascii file with
 mixed record types
  To: trece por ciento el13porcie...@yahoo.com
  Cc: r-help@r-project.org
  Date: Monday, February 1, 2010, 12:01 PM
  
  
  On Feb 1, 2010, at 11:40 AM, trece por ciento wrote:
  
  I need to import several ascii files in fixed
 format with two different record types. The data comes from
 European Labor Force Surveys, wich is a household survey.
 The first record type is for people over 16 years, and the
 second much sorter is for people aged 15 or less (this
 record has a filler with several blanks to get the same
 record length).
  The files tipically have 16 records, with 176
 characters per record, the data is numeric, corresponding to
 102 variables, mostly integers (seven variables have two
 decimals). My opertating system is Windows XP.
  My questions:
  1. Wich do you think is the best way to import the
 files into R?
  
  
  ?read.fwf
  
  2. Could you give me any references or examples?
  
  There are examples in the help page.
  
  Thanking you in advance,
  Hug
  
  
  
  
      [[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.
  
  David Winsemius, MD
  Heritage Laboratories
  West Hartford, CT
  
  
  
  
  
 
 David Winsemius, MD
 Heritage Laboratories
 West Hartford, CT
 
 




__
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] Error with toString

2010-02-02 Thread anna

isn't there a way to specify from which library I am taking the method
from...like rjava.toString or base.toString..

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/Error-with-toString-tp1290327p1460262.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] mysterious extra spaces appearing in expression paste

2010-02-02 Thread anna

try putting sep= in your paste method

-
Anna Lippel
-- 
View this message in context: 
http://n4.nabble.com/mysterious-extra-spaces-appearing-in-expression-paste-tp1460261p1460264.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] mysterious extra spaces appearing in expression paste

2010-02-02 Thread David Winsemius


On Feb 2, 2010, at 2:13 PM, George Locke wrote:


Hi,

i'm trying to put a legend on some figures and they're coming out a
bit wonky.  here's an example:

a - c(1:10)
par(mfrow=c(2,1))
plot(a,type=s,lwd=3)
leg - c(expression(paste(data1 (,rho,=1))),
expression(paste(data2 (,rho,=0.0
legend(bottomright,legend=leg,col=c(1,2),lwd=3)
plot(a,type=s,lwd=3)
leg - c(expression(paste(data1 \n(,rho,=1))),
expression(paste(data2 \n(,rho,=0.0
legend(bottomright,legend=leg,col=c(1,2),lwd=3, y.intersp =  
2.0,adj=c(0,1.5))


the problem is that lots of extra space appears between the open
parenthesis and the rho.


You need to use sep=



what can be done?  (i'm running  version 2.10.1 (2009-12-14) on  
fedora 12)


Thanks!

George Locke

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


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


  1   2   >