Re: [R] Importing Data for a two sample t-test

2012-11-15 Thread Jeff Newmiller
?subset
---
Jeff NewmillerThe .   .  Go Live...
DCN:jdnew...@dcn.davis.ca.usBasics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

nilsonern nilson...@gmail.com wrote:

I am trying to do a two sample t-test with data that i received in a
text
document.  one list has the slab weights and the second has the company
it
is associated with.  here is an example.

weights  company
1  A
2  A  
2  B
3  B

I was able to import the data but i cannot figure out how separate the
data. 
I want to put them in two separate sets, one being A and one being B. 
Any
help would be appreciated.  Thanks.



--
View this message in context:
http://r.789695.n4.nabble.com/Importing-Data-for-a-two-sample-t-test-tp4649565.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] R.dll Reference Guide?

2012-11-15 Thread Prof Brian Ripley

On 14/11/2012 23:10, BayesForever wrote:

Is there a reference guide to the complete set of functions and their
arguments that are available in the R.dll library for Windows, i.e. the set
of functions that includes Rf_initEmbeddedR and Rf_endEmbeddedR listed
in section 8.2.2 of the Writing R Extensions manual?


What does 'available' mean? From that manual:

We can classify the entry points as

API
Entry points which are documented in this manual and declared in an 
installed header file. These can be used in distributed packages and 
will only be changed after deprecation.


public
Entry points declared in an installed header file that are exported 
on all R platforms but are not documented and subject to change without 
notice.


private
Entry points that are used when building R and exported on all R 
platforms but are not declared in the installed header files. Do not use 
these in distributed code.


hidden
Entry points that are where possible (Windows and some modern 
Unix-alike compilers/loaders when using R as a shared library) not exported.


So everything which we intend to be documented is documented in that 
manual, and it is the 'reference guide'.





This may be more of an indictment of my lexical searching skills than
anything else, but I was unable to turn up anything comprehensive after an
hour with various search engines.




--
View this message in context: 
http://r.789695.n4.nabble.com/R-dll-Reference-Guide-tp4649543.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.




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

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


Re: [R] Replacing string in matrix with zero

2012-11-15 Thread Nick Duncan
Dear Rolf,
You are of course quite right, however I wish the diagonal to be
ignored by setting the value to zero. The inf was just recognising the
flow value from self to self.
A very fair point though.
Best,
Nick

On 15 November 2012 04:10, Rolf Turner rolf.tur...@xtra.co.nz wrote:
 On 15/11/12 11:13, Nick Duncan wrote:

 Dear All,

 I have a matrix in which the diagonal has the string Inf in it. In
 order to be able to do cluster analysis this needs to be replaced with
 a Zero.


 I am very sceptical about this assertion.  Inf means infinity
 which is of course *NOT* the same as 0.  By anyone's standards.

 I know nothing about cluster analysis, so I may be toadally out
 to lunch in this, but I suspect that you need to re-think.

 cheers,

 Rolf Turner

 SNIP



-- 
An Englishman, even if he is alone,
forms an orderly queue of one.
--George Mikes

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Function for extracting Lambda Sets

2012-11-15 Thread Nick Duncan
Dear All,

I would like to extract Lambda Sets from a binary matrix that
represents a social network.
The calculation of Lambda Sets is set out in Borgatti 1990 (which can
be downloaded freely).
The package SNA goes part of the way with the function MaxFlow but
does not have the Lambda partitioning - but perhaps it is called
differently in R.
Does anyone know if it exists as a function or if there is a sequence
functions to replicate it?
Many thanks for any guidance on this.
Best,
Nick

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Extracting list names within a looped function

2012-11-15 Thread Gaj Stan (BIGCAT)
Hello all,

I have the following problem:

1) A list was defined as 'a'

a - list(var1=c(100:1), var2=c(1:100), var3=rnorm(100))

2) a function 'foo' was defined that extracts the variable name assigned to x 
using the deparse(substitute()) functionality. This name will then be used 
within the function to generate specific output files, etc.

foo - function(x) {
  print( deparse(substitute(x)) )
}

However, I am currently interested in looping through all list variables and 
extract the list variable name from within the function. The current loop (see 
below) will result in

for(i in 1:length(a)) {
  foo(a[[i]])
}
[1] a[[i]]

which actually does what I expected of deparse(substitute(x)), but is not what 
I wanted. I would like to end up with something like

[1] var1
[1] var2
[1] var3

or

[1] a[[\var1\]]
[1] a[[\var2\]]
[1] a[[\var3\]]

Keep in mind that x has to be a matrix, and not a list. This to keep the 
function as general as possible.

Does anyone have any idea on how to tackle this? Is deparse(substitute(x)) here 
the best way to go? Are there alternatives?

Any help would be greatly appreciated!

Many thanks,

  -- Stan
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Extracting list names within a looped function

2012-11-15 Thread Berend Hasselman

On 15-11-2012, at 11:14, Gaj Stan (BIGCAT) wrote:

 Hello all,
 
 I have the following problem:
 
 1) A list was defined as 'a'
 
 a - list(var1=c(100:1), var2=c(1:100), var3=rnorm(100))
 
 2) a function 'foo' was defined that extracts the variable name assigned to x 
 using the deparse(substitute()) functionality. This name will then be used 
 within the function to generate specific output files, etc.
 
 foo - function(x) {
  print( deparse(substitute(x)) )
 }
 
 However, I am currently interested in looping through all list variables and 
 extract the list variable name from within the function. The current loop 
 (see below) will result in
 
 for(i in 1:length(a)) {
  foo(a[[i]])
 }
 [1] a[[i]]
 
 which actually does what I expected of deparse(substitute(x)), but is not 
 what I wanted. I would like to end up with something like
 
 [1] var1
 [1] var2
 [1] var3
 
 or
 
 [1] a[[\var1\]]
 [1] a[[\var2\]]
 [1] a[[\var3\]]
 
 Keep in mind that x has to be a matrix, and not a list. This to keep the 
 function as general as possible.
 
 Does anyone have any idea on how to tackle this? Is deparse(substitute(x)) 
 here the best way to go? Are there alternatives?

I'm not sure if I understand what you want but will this give you what you seem 
to want:

names(a)

Berend

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Extracting list names within a looped function

2012-11-15 Thread Gaj Stan (BIGCAT)
Hello Berend,

Thanks for your quick response.

I am aware of the names() function, but this is not the answer to my question, 
since it will not work within the foo function. 

Let me try to explain it again! (:

I want to analyze several datasets in a similar fashion and stored all data as 
seperate list components in a (here: $var1, $var2, $var3). Each component of 
that list has a unique name and will be sent through the foo()-function using a 
for-loop. This foo() function would (in my case) generate several plots and 
output files where I would like to use the name of the component ($var1, $var2 
or $var3) in the labels and output file names. I currently am unable to do so.

As such, my end-goal would be that the foo function returns the name of the 
list components and not [1] a[[i]], as deparse(substitute(x)) does. 

The output of foo() needs to be:

 [1] var1
 [1] var2
 [1] var3

But I'm also happy with
 [1] a[[\var1\]]
 [1] a[[\var2\]]
 [1] a[[\var3\]]
(or something similar)

This leads to the question: how can I adjust my foo() so it gives me the output 
mentioned above?
 
I hope that this clears things up.

  -- Stan


-Original Message-
From: Berend Hasselman [mailto:b...@xs4all.nl] 
Sent: 15 November 2012 11:27
To: Gaj Stan (BIGCAT)
Cc: r-help@r-project.org
Subject: Re: [R] Extracting list names within a looped function


On 15-11-2012, at 11:14, Gaj Stan (BIGCAT) wrote:

 Hello all,
 
 I have the following problem:
 
 1) A list was defined as 'a'
 
 a - list(var1=c(100:1), var2=c(1:100), var3=rnorm(100))
 
 2) a function 'foo' was defined that extracts the variable name assigned to x 
 using the deparse(substitute()) functionality. This name will then be used 
 within the function to generate specific output files, etc.
 
 foo - function(x) {
  print( deparse(substitute(x)) )
 }
 
 However, I am currently interested in looping through all list variables and 
 extract the list variable name from within the function. The current loop 
 (see below) will result in
 
 for(i in 1:length(a)) {
  foo(a[[i]])
 }
 [1] a[[i]]
 
 which actually does what I expected of deparse(substitute(x)), but is not 
 what I wanted. I would like to end up with something like
 
 [1] var1
 [1] var2
 [1] var3
 
 or
 
 [1] a[[\var1\]]
 [1] a[[\var2\]]
 [1] a[[\var3\]]
 
 Keep in mind that x has to be a matrix, and not a list. This to keep the 
 function as general as possible.
 
 Does anyone have any idea on how to tackle this? Is deparse(substitute(x)) 
 here the best way to go? Are there alternatives?

I'm not sure if I understand what you want but will this give you what you seem 
to want:

names(a)

Berend

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Getting information encoded in a SAS, SPSS or Stata command file into R.

2012-11-15 Thread Anthony Damico
 What I do not understand is how SAS knows where the variables begin and
 end.
 I managed to break off a little hunk of the beginning of my file and look
 at
 it in an editor, and it is numbers without any obvious delimiters. Is the
 delimiter a particular numeric string? I thought the SAS command file would
 contain the starting location for each of the fixed-length fields, but I do
 not see anything in the file that could be interpreted that way – just a
 little wraparound code and then a long list of variable names followed by
 triplets of a code, an equals sign, and a text string, terminating with a
 semicolon.



Search around for the word INPUT.  If that doesn't exist, you're probably
looking at a formatting-only script -- and the delimiting happens elsewhere.

Here are some examples of what the R SAScii package looks for when it uses
a SAS importation script to read in ASCII data:

library(SAScii)
?parse.SAScii

note that there are additional examples under ?read.SAScii that include
IPUMS data  ;)

also: David's idea is totally awesome

[[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] How to modify a S4 function (in the package NADA)

2012-11-15 Thread maxbre
I want to get access to the code of an S4 method in order to possibly modify
a function to accomplish my particular needs: in my case the function in is
cenfit() from the package NADA 

Now, given my reproducible example:

my.ex-structure(list(TEC = c(0.21, 0.077, 0.06, 0.033, 0.014, 0.0072), LR =
c(0L, 0L, 1L, 0L, 1L, 0L)), .Names = c(TEC, LR), class = data.frame,
row.names = c(NA, -6L))

and the following few lines of code:

library(“NADA)

attach(my.ex)

cenfit(TEC,LR)

giving this output:

  n  n.cen median   mean  sd 
6.00 2.00  0.033   0.058   0.083

I would like to add one more result to the above, namely “sum”, very simply
computed as the product of “n” times “mean”

Do you think that is possible or convenient?

I’ve been reading that editing a S4 methods needs particular attention as by
using showMethods(cenfit) and then getMethod(cenfit); in fact, I’ve been
trying that but without much success (i.e. understanding of the cumbersome
output)

can anyone give me some help on how is probably better to proceed in order
to get my new result? 

different alternative solutions or hints or advices are also more than
welcomed 
(I’m pretty new on R and specially on the field of function handling and
customizing)

all the best

max




--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-modify-a-S4-function-in-the-package-NADA-tp4649586.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] R exponential regression

2012-11-15 Thread PIKAL Petr
Hi

your model
f - function(x,a,b) {a * I(x^b)}

can be expressed as

log(a)+b*log(x)

and for that it shall result in straight line and you can use lm for estimate 
of b and log(a)

It is also better to use 1:33 instead of 1980:2012

Based on values you get from linear realation you can set sensible starting 
values.

 fm - nls(y~a*z^b, data=test, start=c(a=0.2,b=2))
 summary(fm)

Formula: y ~ a * z^b

Parameters:
  Estimate Std. Error t value Pr(|t|)
a  0.133910.01848   7.248 3.74e-08 ***
b  2.225630.04140  53.763   2e-16 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1 

Residual standard error: 6.239 on 31 degrees of freedom

Number of iterations to convergence: 6 
Achieved convergence tolerance: 7.673e-07 

Regards
Petr


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of muzammil786
 Sent: Wednesday, November 14, 2012 12:12 PM
 To: r-help@r-project.org
 Subject: Re: [R] R exponential regression
 
 I am having a similar problem on this data (given below). I have tried
 several starting values for a and b, but it is consistently giving me:
 
 fm - nls(y~f(x,a,b), data.frame(x,y), start=c(a=1,b=1)) Error in
 numericDeriv(form[[3L]], names(ind), env) :
   Missing value or an infinity produced when evaluating the model
 
 The function f(x,a,b) is defined here:
 f - function(x,a,b) {a * I(x^b)}
 
 The data is given here:
 
   x   y
 1  1980   1
 2  1981   1
 3  1982   1
 4  1983   3
 5  1984   3
 6  1985   5
 7  1986   8
 8  1987   8
 9  1988   9
 10 1989  12
 11 1990  15
 12 1991  24
 13 1992  33
 14 1993  44
 15 1994  62
 16 1995  68
 17 1996  81
 18 1997  87
 19 1998 102
 20 1999 114
 21 2000 123
 22 2001 135
 23 2002 144
 24 2003 158
 25 2004 172
 26 2005 188
 27 2006 197
 28 2007 224
 29 2008 234
 30 2009 254
 31 2010 278
 32 2011 312
 33 2012 317
 
 I shall be grateful if you could guide me what's wrong here.
 
 Cheers.
 Muzammil
 
 
 
 --
 View this message in context: http://r.789695.n4.nabble.com/R-
 exponential-regression-tp1009449p4649474.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] heatmap with symbols

2012-11-15 Thread Jean V Adams
Use the col= argument to the heatmap() function to specify the three 
colors you want.  For example:
x - matrix(rnorm(50), ncol=5)
heatmap(x, col=1:3)

Jean



furor furor1...@gmail.com wrote on 11/14/2012 03:31:42 AM:
 
 Hi all,
 
 I've made a heatmap using '-', '=' and '+' as possible values. However, 
the
 heatmap itself shows more than three colors. How to avoid this?
 
 Thanks in advance.
 
 regards

[[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] How to modify a S4 function (in the package NADA)

2012-11-15 Thread Sarah Goslee
Hi,

Your reproducible example isn't reproducible for me, as I get an error message.

But regardless, the easiest thing to do is write your own wrapper,
something like:

mycenfit - function(x, y) {
  result - cenfit(x, y)
  c(result, sum = result$n * result$mean)
}

No need to change anything in the package itself. Incidentally, using
attach() is generally a really bad idea. with() is much safer.

Sarah

On Thu, Nov 15, 2012 at 7:00 AM, maxbre mbres...@arpa.veneto.it wrote:
 I want to get access to the code of an S4 method in order to possibly modify
 a function to accomplish my particular needs: in my case the function in is
 cenfit() from the package NADA

 Now, given my reproducible example:

 my.ex-structure(list(TEC = c(0.21, 0.077, 0.06, 0.033, 0.014, 0.0072), LR =
 c(0L, 0L, 1L, 0L, 1L, 0L)), .Names = c(TEC, LR), class = data.frame,
 row.names = c(NA, -6L))

 and the following few lines of code:

 library(“NADA)

 attach(my.ex)

 cenfit(TEC,LR)

 giving this output:

   n  n.cen median   mean  sd
 6.00 2.00  0.033   0.058   0.083

 I would like to add one more result to the above, namely “sum”, very simply
 computed as the product of “n” times “mean”

 Do you think that is possible or convenient?

 I’ve been reading that editing a S4 methods needs particular attention as by
 using showMethods(cenfit) and then getMethod(cenfit); in fact, I’ve been
 trying that but without much success (i.e. understanding of the cumbersome
 output)

 can anyone give me some help on how is probably better to proceed in order
 to get my new result?

 different alternative solutions or hints or advices are also more than
 welcomed
 (I’m pretty new on R and specially on the field of function handling and
 customizing)

 all the best

 max






--
Sarah Goslee
http://www.functionaldiversity.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.


Re: [R] Send Email from R

2012-11-15 Thread R_Antony
THE ERROR WAS :  
ERROR: compilation failed for package 'base64'
Problem is with version.

Any idea,  how can we do this without any packages ?

- Thanks 
Antony.




--
View this message in context: 
http://r.789695.n4.nabble.com/Send-Email-from-R-tp4645565p4649585.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] configure: error: --with-x=yes (default) and X11 headers/libs are not a

2012-11-15 Thread arunkumar1111
Hi

I'm trying to install R-2.15.2 in Unix environment  and when i run
./configure i'm getting the following error


configure: error: --with-x=yes (default) and X11 headers/libs are not
available. 

i just unzip .tar file and ran ./configure.  I'm not able to get x11()
anywhere.

Please help me




-
Thanks in Advance
Arun
--
View this message in context: 
http://r.789695.n4.nabble.com/configure-error-with-x-yes-default-and-X11-headers-libs-are-not-a-tp4649592.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] correct use with fligner test

2012-11-15 Thread gaiarrido
Hi R users,
Iwant to run a model, but want to know previously if my data present
homoscedascity:
the model is something like this: 
glm(ax~a*b*c*d)

I´ve found four different ways to test for homoscedascity, but i want to
know which is correct:

1.-fligner.test(glm(x~a*b*c*d))

2.-fligner.test(x~a*b*c*d)

3.-fligner.test(x~a,b,c,d)

4.-interc-interaction(a,b,c,d)
 fligner.test(x,interc)

Thanks in advance




-
Mario Garrido Escudero
PhD student
Dpto. de Biología Animal, Ecología, Parasitología, Edafología y Qca. Agrícola
Universidad de Salamanca
--
View this message in context: 
http://r.789695.n4.nabble.com/correct-use-with-fligner-test-tp4649583.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] combine similar variables in chart

2012-11-15 Thread Marcella
I want to make a chart on variables which are taken in 2 different years on 2
the same locations, at different depths, where for every location the
species and the amount of species are determined.

The first chart I want to make is to see how much of every species is
collected in total in a bar or piechart.
Then I want to make a few charts with the species per location and per depth

Here is a subset of my dataset

Station Latitude(S) Longitude(E)Depth(m)Sa.Code Sp.Code N
UPG02   -5.122355036119.339401  4   UPG02_4 Amphis_lesson   398
UPG02   -5.122355036119.339401  4   UPG02_4 Amphis_radiat   58
UPG02   -5.122355036119.339401  4   UPG02_4 Penero_planat   3
UPG02   -5.122355036119.339401  4.8 UPG02_4.8   Sphero_sp   
5
UPG02   -5.122355036119.339401  4.8 UPG02_4.8   Amphis_lesson   
204
UPG02   -5.122355036119.339401  4.8 UPG02_4.8   Amphis_radiat   
18
UPG02   -5.122355036119.339401  9   UPG02_9 Sphero_sp   1
UPG02   -5.122355036119.339401  9   UPG02_9 Eponid_repand   2
UPG02   -5.122355036119.339401  9   UPG02_9 Planor_sp   7
UPG02   -5.122355036119.339401  15  UPG02_15Opercu_ammono   
1
UPG02   -5.122355036119.339401  15  UPG02_15Hetero_depres   
94
UPG02   -5.122355036119.339401  15  UPG02_15Amphis_lesson   
101
UPG02   -5.122355036119.339401  18  UPG02_18Sphero_sp   
3
UPG02   -5.122355036119.339401  18  UPG02_18Millio_sp   
1
UPG02   -5.122355036119.339401  18  UPG02_18Calcar_mayori   
56
UPG03   -5.136863021119.387289  3   UPG03_3 Millio_sp   2
UPG03   -5.136863021119.387289  3   UPG03_3 Sahuli_sp1  1
UPG03   -5.136863021119.387289  3   UPG03_3 Elphid_cratic   20
UPG03   -5.136863021119.387289  4   UPG03_4 Planor_sp   1
UPG03   -5.136863021119.387289  4   UPG03_4 Opercu_elegan   1
UPG03   -5.136863021119.387289  4   UPG03_4 Septot_sp   1
UPG03   -5.136863021119.387289  5   UPG03_5 Sphero_sp   1
UPG03   -5.136863021119.387289  5   UPG03_5 Millio_sp   1
UPG03   -5.136863021119.387289  5   UPG03_5 Ammoni_sp1  1
UPG03   -5.136863021119.387289  6   UPG03_6 Calcar_sp1  2
UPG03   -5.136863021119.387289  6   UPG03_6 Calcar_mayori   68
UPG03   -5.136863021119.387289  6   UPG03_6 Elphid_cratic   17
UPG03   -5.136863021119.387289  9   UPG03_9 Sphero_sp   2
UPG03   -5.136863021119.387289  9   UPG03_9 Calcar_mayori   323
UPG03   -5.136863021119.387289  9   UPG03_9 Calcar_spengl   2
UPG28   -5.122355036119.339401  5   UPG28_5 Penero_planat   8
UPG28   -5.122355036119.339401  5   UPG28_5 Amphis_latera   1
UPG28   -5.122355036119.339401  5   UPG28_5 Sorite_sp   1
UPG28   -5.122355036119.339401  8   UPG28_8 Bilocu_sp3  1
UPG28   -5.122355036119.339401  8   UPG28_8 Verteb_sp   1
UPG28   -5.122355036119.339401  8   UPG28_8 Penero_planat   7
UPG28   -5.122355036119.339401  11  UPG28_11Placop_c.f. 
1
UPG28   -5.122355036119.339401  11  UPG28_11Sphero_sp   
2
UPG28   -5.122355036119.339401  11  UPG28_11Siphon_siphon   
1
UPG28   -5.122355036119.339401  14  UPG28_14Sphero_sp   
1
UPG28   -5.122355036119.339401  14  UPG28_14Sorite_sp   
1
UPG28   -5.122355036119.339401  14  UPG28_14Spirol_hadaii   
1
UPG28   -5.122355036119.339401  17  UPG28_17Sphero_sp   
3
UPG28   -5.122355036119.339401  17  UPG28_17Siphon_siphon   
1
UPG28   -5.122355036119.339401  17  UPG28_17Sorite_sp   
1
UPG32   -5.136863021119.387289  4   UPG32_4 Pyrgo_striol1
UPG32   -5.136863021119.387289  4   UPG32_4 Ammoma_alveol   1
UPG32   -5.136863021119.387289  4   UPG32_4 Quinqu_netstr   1
UPG32   -5.136863021119.387289  6   UPG32_6 Neorot_calcar   1
UPG32   -5.136863021119.387289  6   UPG32_6 Quinqu_c.f.ag   1
UPG32   -5.136863021119.387289  6   UPG32_6 Amphis_lesson   50
UPG32   -5.136863021119.387289  8   UPG32_8 Spirol_sp3  1
UPG32   -5.136863021119.387289  8   UPG32_8 Triloc_tricar   1
UPG32   -5.136863021119.387289  8   UPG32_8 Amphis_lesson   34




--
View this message in context: 
http://r.789695.n4.nabble.com/combine-similar-variables-in-chart-tp4649581.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 

[R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread David Romano
Hi everyone,

I have a data frame one of whose columns is a character vector and the rest
are numeric, and in debugging a script, I noticed that an ifelse call seems
to be coercing the character column to a numeric column, and producing
unintended values as a result.   Roughly, here's what I tried to do:

df: a data frame with, say, the first column as a character column and the
second and third columns numeric.

also: NA's occur only in the numeric columns, and if they occur in one,
they occur in the other as well.

I wanted to replace the NA's in column 2 with 0's and the ones in column 3
with 1's, so first I did this:

 na.replacements -ifelse(col(df)==2,0,1).

Then I used a second ifelse call to try to remove the NA's as I wanted,
first by doing this:

 clean.df - ifelse(is.na(df), na.replacements, df),

which produced a list of lists vaguely resembling df, with the NA's mostly
intact, and so then I tried this:

 clean.df - ifelse(is.na(df), na.replacements, unlist(df)),

which seems to work if all the columns are numeric, but otherwise changes
strings to numbers.

I can't make sense of the help documentation enough to clear this up, but
my guess is that the yes and no values passed to ifelse need to be
vectors, in which case it seems I'll have to use another approach entirely,
but even if is not the case and lists are acceptable, I'm not sure how to
convert a mixed-mode data frame into a vector-like list of elements (which
I would hope would work).

I'd be grateful for any suggestions!

Thanks,
David Romano

[[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] Extracting list names within a looped function

2012-11-15 Thread Marcella Meerkerk
No this doesn't seem like what I want.

As you can see in the dataset sometimes there are the same species on
different locations. First I want to make a chart on how many of a single
species there are in this dataset and preferrably for all species in one
chart.

Second I want to make such a chart per Location or Station as called in the
data set and third such a chart per Sa.Code

Gr,
Marcella

2012/11/15 Berend Hasselman b...@xs4all.nl


 On 15-11-2012, at 11:14, Gaj Stan (BIGCAT) wrote:

  Hello all,
 
  I have the following problem:
 
  1) A list was defined as 'a'
 
  a - list(var1=c(100:1), var2=c(1:100), var3=rnorm(100))
 
  2) a function 'foo' was defined that extracts the variable name assigned
 to x using the deparse(substitute()) functionality. This name will then be
 used within the function to generate specific output files, etc.
 
  foo - function(x) {
   print( deparse(substitute(x)) )
  }
 
  However, I am currently interested in looping through all list variables
 and extract the list variable name from within the function. The current
 loop (see below) will result in
 
  for(i in 1:length(a)) {
   foo(a[[i]])
  }
  [1] a[[i]]
 
  which actually does what I expected of deparse(substitute(x)), but is
 not what I wanted. I would like to end up with something like
 
  [1] var1
  [1] var2
  [1] var3
 
  or
 
  [1] a[[\var1\]]
  [1] a[[\var2\]]
  [1] a[[\var3\]]
 
  Keep in mind that x has to be a matrix, and not a list. This to keep the
 function as general as possible.
 
  Does anyone have any idea on how to tackle this? Is
 deparse(substitute(x)) here the best way to go? Are there alternatives?

 I'm not sure if I understand what you want but will this give you what you
 seem to want:

 names(a)

 Berend

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] RMySQL install on windows

2012-11-15 Thread sbarandiaran
Uwe, I set the variable with single backslashes, but the output remains the
same. The last part reads:

gcc -m64 -shared -s -static-libgcc -o RMySQL.dll tmp.def RS-DBI.o
RS-MySQL.o C:\Program Files\MySQL\MySQL Server 5.5/bin/libmysql.dll
-Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64
-Ld:/Rcompile/CRANpkg/extralibs64/local/lib
-LC:/PROGRA~1/R/R-215~1.1/BIN/X64 -lR
gcc.exe: error:  C:\Program Files\MySQL\MySQL Server 5.5/bin/libmySQL.dll:
No such file or directory 
ERROR: compilation failed for package 'RMySQL' 
* removing 'C:/Users/Acer/Documents/R/win-library/2.15/RMySQL'  





--
View this message in context: 
http://r.789695.n4.nabble.com/RMySQL-install-on-windows-tp4645629p4649590.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] survreg gompertz

2012-11-15 Thread Matthias Ziehm

Hi all,

Sorry if this has been answered already, but I couldn't find it in the 
archives or general internet.


Is it possible to implement the gompertz distribution as 
survreg.distribution to use with survreg of the survival library?
I haven't found anything and recent attempts from my side weren't 
succefull so far.


I know that other packages like 'eha' and 'flexsurv' offer functions 
similar to survreg with gompertz support. However, due to the run-time 
environment were this needs to be running in the end, I can't use these 
packages :(


Same questions for the gompertz-makeham distribution.

Many thanks!

Matthias

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Can't see what i did wrong..

2012-11-15 Thread Jessica Streicher
Its not scaling.. so.. 

I guess i'll stay severely frustrated, and yes i know this is probably not 
enough information for anyone to help.
Still, talking helps ;)

On 15.11.2012, at 15:15, Jessica Streicher wrote:

 with
 
 pred.pca-predict(splits[[i]]$pca,trainingData@samples)[,1:nPCs]
 dframe-as.data.frame(cbind(pred.pca,class=isExplosive(trainingData,2)));
 results[[i]]$classifier-ksvm(class~.,data=dframe,scaled=T,kernel=polydot,type=C-svc,
   
 C=C,kpar=list(degree=degree,scale=scale,offset=offset),prob.model=T)
 
 and a degree of 5 i get an error of 0 reported by the ksvm object. But when 
 doing
 
 pred.pca-predict(splits[[i]]$pca,trainingData@samples)[,1:nPCs]
 pred.svm-kernlab::predict(results[[i]]$classifier,pred.pca,type=probabilities);
 results[[i]]$trainResults$predicted-pred.svm[,2]
   
 the results vary widely from the class vector. Nearly all predictions are 
 somewhat around 0.29. Its just strange. And i have no idea where things go 
 wrong. They're in the same loop with i, so its probably not an indexing issue.
 
 Maybe kernlabs predict doesn't scale the data or something? 
 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] SVM? Comparison method wanted: 3 Groups, Microarray data

2012-11-15 Thread Peter Kupfer
Dear all,
i have microarray data of 3 classes of patients. It's not a time course 
experiment only steady state.
I used a rule-based method to classify the groups by the expression of the 
genes. This works out so far. Nevertheless I want to check my results with an 
other method. Therefore I look for one and want to ask you, what you suggest.
I have 3 different patient groups, only the steady state data, 10/10/13 (total 
of 33) arrays and the challenge is to classify the groups by the expression of 
all genes on the hgu133a chip. 
The named rule-based method found for each group genes, which explain a 
classification for each sample to one of the groups. 
Are there packages/method you can suggest? I guess PAMR works not so good for 
all genes on the chip, right?
Would be amazing if you can tell me your opinion.
All the best and thanks
Peter







from the desk of peter kupfer

   

leibnitz institute of  natural product research and infection biology
- hans-knoell institute - 
research group: systems biology / bioinformatics

beutenbergstrasse 11a
D-07745 jena

fon: +49 3641 532 1329
fax: +49 3641 532 2329
mail: peter.kup...@hki-jena.de


[[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] configure: error: --with-x=yes (default) and X11 headers/libs are not a

2012-11-15 Thread Sarah Goslee
Then you need to install the x11 headers for your Unix (linux?)
system. I can't tell you what or how without knowing more about your
particular setup.

By far the easiest thing to do if you're not familiar with compiling
your own software, headers and such, is to install the binary for your
linux distro from the usual repository. Assuming you're running linux:
just telling us Unix isn't actually all that informative.

Sarah

On Thu, Nov 15, 2012 at 8:26 AM, arunkumar akpbond...@gmail.com wrote:
 Hi

 I'm trying to install R-2.15.2 in Unix environment  and when i run
 ./configure i'm getting the following error


 configure: error: --with-x=yes (default) and X11 headers/libs are not
 available.

 i just unzip .tar file and ran ./configure.  I'm not able to get x11()
 anywhere.

 Please help me



--
Sarah Goslee
http://www.functionaldiversity.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.


Re: [R] How to modify a S4 function (in the package NADA)

2012-11-15 Thread maxbre
sorry sarah

you are right, my fault, this is the correct reproducible example
(a misinterpretation of LR type occurred in previous reproducible example)

my.ex-structure(list(TEC = c(0.21, 0.077, 0.06, 0.033, 0.014, 0.0072
), LR = c(FALSE, FALSE, TRUE, FALSE, TRUE, FALSE)), .Names = c(TEC, 
LR), row.names = c(NA, -6L), class = data.frame)

but, nevertheless,  still some problems exists because...

str(my.ex)
library(NADA)

with(my.ex,
 cenfit(TEC,LR)
 )

mycenfit - function(x, y) {
  result - cenfit(x, y)
  c(result, sum = result$n * result$mean)
}

with(my.ex, 
   mycenfit(TEC,LR)
   )

giving me the following error message

Error in result$n : $ operator not defined for this S4 class

again pointing to the peculiar structure of S4 class (at least I think to
understand)

thank you for your reply

max



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-modify-a-S4-function-in-the-package-NADA-tp4649586p4649598.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] How to modify a S4 function (in the package NADA)

2012-11-15 Thread Sarah Goslee
Thanks for the clarification, Martin. Since I couldn't reproduce the
example, I didn't get to see what was actually being returned (and
was, admittedly, too lazy to dig through the help).

 library(NADA)
 my.ex-structure(list(TEC = c(0.21, 0.077, 0.06, 0.033, 0.014, 0.0072), LR =
+ c(0L, 0L, 1L, 0L, 1L, 0L)), .Names = c(TEC, LR), class = data.frame,
+ row.names = c(NA, -6L))

 with(my.ex, cenfit(TEC,LR))
Error in function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘cenfit’ for
signature ‘numeric, integer, missing’

Not that I'm worried about it not working, but it's a good idea to
test reproducible examples on a clean session to ensure the best
possible answers.

Sarah

On Thu, Nov 15, 2012 at 9:32 AM, Martin Morgan mtmor...@fhcrc.org wrote:
 On 11/15/2012 06:10 AM, Sarah Goslee wrote:

 Hi,

 Your reproducible example isn't reproducible for me, as I get an error
 message.

 But regardless, the easiest thing to do is write your own wrapper,
 something like:

 mycenfit - function(x, y) {
result - cenfit(x, y)
c(result, sum = result$n * result$mean)
 }

 No need to change anything in the package itself. Incidentally, using
 attach() is generally a really bad idea. with() is much safer.

 Sarah

 On Thu, Nov 15, 2012 at 7:00 AM, maxbre mbres...@arpa.veneto.it wrote:

 I want to get access to the code of an S4 method in order to possibly
 modify
 a function to accomplish my particular needs: in my case the function in
 is
 cenfit() from the package NADA

 Now, given my reproducible example:

 my.ex-structure(list(TEC = c(0.21, 0.077, 0.06, 0.033, 0.014, 0.0072),
 LR =
 c(0L, 0L, 1L, 0L, 1L, 0L)), .Names = c(TEC, LR), class =
 data.frame,
 row.names = c(NA, -6L))

 and the following few lines of code:

 library(“NADA)

 attach(my.ex)

 cenfit(TEC,LR)

 giving this output:

n  n.cen median   mean  sd
 6.00 2.00  0.033   0.058   0.083


 actually, cenfit() returns an object

 xx = cenfit(my.ex$TEC, as.logical(my.ex$LR))

 and what you're seeing is the result of the object's 'show' method

 xx
  n  n.cen median   mean sd
 6. 2. 0.0330 0.05836667 0.08350178

 You can see the body of the show method with

 selectMethod(show, class(xx))

 and methods that are available to work on xx with

 showMethods(class=class(xx), where=search())

 Sarah is right that you'd likely want to write your own function, using a
 combination of available methods, e.g.,

 censtats - function(x) {
 s = summary(x)
 c(n = nrow(s), n.cen = nrow(s) - sum(s$n.event), median = median(x),
   mean = mean(x)[[mean]], sd = sd(x))
 }

 Martin


 I would like to add one more result to the above, namely “sum”, very
 simply
 computed as the product of “n” times “mean”

 Do you think that is possible or convenient?

 I’ve been reading that editing a S4 methods needs particular attention as
 by
 using showMethods(cenfit) and then getMethod(cenfit); in fact, I’ve
 been
 trying that but without much success (i.e. understanding of the
 cumbersome
 output)

 can anyone give me some help on how is probably better to proceed in
 order
 to get my new result?

 different alternative solutions or hints or advices are also more than
 welcomed
 (I’m pretty new on R and specially on the field of function handling and
 customizing)

 all the best

 max







--
Sarah Goslee
http://www.functionaldiversity.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] Can't see what i did wrong..

2012-11-15 Thread Jessica Streicher
with

pred.pca-predict(splits[[i]]$pca,trainingData@samples)[,1:nPCs]
dframe-as.data.frame(cbind(pred.pca,class=isExplosive(trainingData,2)));
results[[i]]$classifier-ksvm(class~.,data=dframe,scaled=T,kernel=polydot,type=C-svc,

C=C,kpar=list(degree=degree,scale=scale,offset=offset),prob.model=T)

and a degree of 5 i get an error of 0 reported by the ksvm object. But when 
doing

pred.pca-predict(splits[[i]]$pca,trainingData@samples)[,1:nPCs]
pred.svm-kernlab::predict(results[[i]]$classifier,pred.pca,type=probabilities);
results[[i]]$trainResults$predicted-pred.svm[,2]

the results vary widely from the class vector. Nearly all predictions are 
somewhat around 0.29. Its just strange. And i have no idea where things go 
wrong. They're in the same loop with i, so its probably not an indexing issue.

Maybe kernlabs predict doesn't scale the data or something? 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Can't see what i did wrong..

2012-11-15 Thread Jessica Streicher
Now i let it run for one specific set and got the same bad result, then i 
deactivated the probabilities and got a good result, then i activated the 
probabilities again and got a good result .. huh???

On 15.11.2012, at 15:32, Jessica Streicher wrote:

 Its not scaling.. so.. 
 
 I guess i'll stay severely frustrated, and yes i know this is probably not 
 enough information for anyone to help.
 Still, talking helps ;)
 
 On 15.11.2012, at 15:15, Jessica Streicher wrote:
 
 with
 
 pred.pca-predict(splits[[i]]$pca,trainingData@samples)[,1:nPCs]
 dframe-as.data.frame(cbind(pred.pca,class=isExplosive(trainingData,2)));
 results[[i]]$classifier-ksvm(class~.,data=dframe,scaled=T,kernel=polydot,type=C-svc,
  
 C=C,kpar=list(degree=degree,scale=scale,offset=offset),prob.model=T)
 
 and a degree of 5 i get an error of 0 reported by the ksvm object. But when 
 doing
 
 pred.pca-predict(splits[[i]]$pca,trainingData@samples)[,1:nPCs]
 pred.svm-kernlab::predict(results[[i]]$classifier,pred.pca,type=probabilities);
 results[[i]]$trainResults$predicted-pred.svm[,2]
  
 the results vary widely from the class vector. Nearly all predictions are 
 somewhat around 0.29. Its just strange. And i have no idea where things go 
 wrong. They're in the same loop with i, so its probably not an indexing 
 issue.
 
 Maybe kernlabs predict doesn't scale the data or something? 
 
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] How to modify a S4 function (in the package NADA)

2012-11-15 Thread Martin Morgan

On 11/15/2012 06:10 AM, Sarah Goslee wrote:

Hi,

Your reproducible example isn't reproducible for me, as I get an error message.

But regardless, the easiest thing to do is write your own wrapper,
something like:

mycenfit - function(x, y) {
   result - cenfit(x, y)
   c(result, sum = result$n * result$mean)
}

No need to change anything in the package itself. Incidentally, using
attach() is generally a really bad idea. with() is much safer.

Sarah

On Thu, Nov 15, 2012 at 7:00 AM, maxbre mbres...@arpa.veneto.it wrote:

I want to get access to the code of an S4 method in order to possibly modify
a function to accomplish my particular needs: in my case the function in is
cenfit() from the package NADA

Now, given my reproducible example:

my.ex-structure(list(TEC = c(0.21, 0.077, 0.06, 0.033, 0.014, 0.0072), LR =
c(0L, 0L, 1L, 0L, 1L, 0L)), .Names = c(TEC, LR), class = data.frame,
row.names = c(NA, -6L))

and the following few lines of code:

library(“NADA)

attach(my.ex)

cenfit(TEC,LR)

giving this output:

   n  n.cen median   mean  sd
6.00 2.00  0.033   0.058   0.083


actually, cenfit() returns an object

 xx = cenfit(my.ex$TEC, as.logical(my.ex$LR))

and what you're seeing is the result of the object's 'show' method

 xx
 n  n.cen median   mean sd
6. 2. 0.0330 0.05836667 0.08350178

You can see the body of the show method with

selectMethod(show, class(xx))

and methods that are available to work on xx with

showMethods(class=class(xx), where=search())

Sarah is right that you'd likely want to write your own function, using a 
combination of available methods, e.g.,


censtats - function(x) {
s = summary(x)
c(n = nrow(s), n.cen = nrow(s) - sum(s$n.event), median = median(x),
  mean = mean(x)[[mean]], sd = sd(x))
}

Martin



I would like to add one more result to the above, namely “sum”, very simply
computed as the product of “n” times “mean”

Do you think that is possible or convenient?

I’ve been reading that editing a S4 methods needs particular attention as by
using showMethods(cenfit) and then getMethod(cenfit); in fact, I’ve been
trying that but without much success (i.e. understanding of the cumbersome
output)

can anyone give me some help on how is probably better to proceed in order
to get my new result?

different alternative solutions or hints or advices are also more than
welcomed
(I’m pretty new on R and specially on the field of function handling and
customizing)

all the best

max







--
Sarah Goslee
http://www.functionaldiversity.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.




--
Computational Biology / Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N.
PO Box 19024 Seattle, WA 98109

Location: Arnold Building M1 B861
Phone: (206) 667-2793

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Send Email from R

2012-11-15 Thread Prof Brian Ripley

On 15/11/2012 11:49, R_Antony wrote:

We had no context.  This is R-help, not a Nabble forum.


THE ERROR WAS :
ERROR: compilation failed for package 'base64'
Problem is with version.

Any idea,  how can we do this without any packages ?


Does searching not work for you?  ??email returned

utils::create.post  Ancillary Function for Preparing Emails and
Postings

Whatever is using the orphaned package base64 (sendmailR?) should be 
updated to use base64enc.




- Thanks
Antony.



PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


PLEASE do.


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

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


Re: [R] configure: error: --with-x=yes (default) and X11 headers/libs are not a

2012-11-15 Thread Prof Brian Ripley

On 15/11/2012 14:28, Sarah Goslee wrote:

Then you need to install the x11 headers for your Unix (linux?)
system. I can't tell you what or how without knowing more about your
particular setup.


But note that the manual does cover a lot of the possibilities.

From the INSTALL file:

'The main source of information on installation is the `R Installation
and Administration Manual', an HTML copy of which is available as file
`doc/html/R-admin.html'.  Please read that before installing R.  But
if you are impatient, read on but please refer to the manual to
resolve any problems.'



By far the easiest thing to do if you're not familiar with compiling
your own software, headers and such, is to install the binary for your
linux distro from the usual repository. Assuming you're running linux:
just telling us Unix isn't actually all that informative.

Sarah

On Thu, Nov 15, 2012 at 8:26 AM, arunkumar akpbond...@gmail.com wrote:

Hi

I'm trying to install R-2.15.2 in Unix environment  and when i run
./configure i'm getting the following error


configure: error: --with-x=yes (default) and X11 headers/libs are not
available.

i just unzip .tar file and ran ./configure.  I'm not able to get x11()
anywhere.

Please help me




--
Sarah Goslee
http://www.functionaldiversity.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.




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

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


[R] hessian fails for box-constrained problems when close to boundary?

2012-11-15 Thread Matthieu Stigler
Hi

I am trying to recover the hessian of a problem optimised with
box-constraints. The problem is that in some cases, my estimates are very
close to the boundary, which will make optim(..., hessian=TRUE) or
optimHessian() fail, as they do not follow the box-constraints, and hence
estimate the function in the unfeasible parameter space.

As a simple example (my problem is more complex though, simple param
transformations do not apply ashere), imagine estimating mu and sigma
(restricted to be 0) of a simple normally distributed data, where however
the true sigma is very close to zero:

LLNorm - function(para, dat=rn)  return(-sum(dnorm(dat, para[1], para[2],
log=TRUE)))
rn2 - c(rep(10.3, 2000), 10.31)

optim(c(10,1), fn=LLNorm, method=L-BFGS-B, lower=c(-Inf, 0.001),
dat=rn2,hessian=TRUE)
Error in optim(c(10, 1), fn = LLNorm, method = L-BFGS-B, lower = c(-Inf,
: non-finite finite-difference value [2]

The only solution/workaround I found is to do a two steps procedure: use
optim() without hessian, then use optimHess, specifying the length of the
numerical variations (arg ndeps) as smaller as the distance between the
parameter and the bound, i.e.:
op-optim(c(10,1), fn=LLNorm, method=L-BFGS-B, lower=c(-Inf, 0.001),
dat=rn2,hessian=FALSE)

H-optimHess(op$par, LLNorm, dat=rn2,
control=list(ndeps=rep((op$par[2]-0)/1000,2)))

While this solution works, it is surely not elegant, and I have following
questions:
1) is this solution to use smaller steps good at all?
2) I am not sure either I understand the reasons why the hessian in a
constrained optim problem is evaluated without the constraints, or at least
the problem transformed into a warning?

Furthermore, I realised that using the numDeriv package, the function
hessian() does not offer either constraints for the parameters, yet in the
special case of the example above, it does not fail (although would have
problems with parameter even closer to the bound), unlike the
optimHessian() function? See:
library(numDeriv)
hessian(LLNorm, op$par, dat=rn2)

This brings me to the final question: is there a technical reason not to
allow a constrained hessian, which seems to indicate the fact that the
two implementations in R do not do it? I found a very interesting answer by
Spencer Grave for  a similar question:
http://tolstoy.newcastle.edu.au/R/e4/help/08/06/15061.html
although this regards more the statistical implications than the numerical
issues.

Thanks a lot!

Matthieu

[[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] Multiple groups barplot

2012-11-15 Thread michele caseposta
Hi Jim,
thanks again for your support.
Yes, I meant the subject codes; I will add a new variable and set the color to 
white all over.
Thanks,
Michele

On Nov 15, 2012, at 1:13 AM, Jim Lemon wrote:

 On 11/15/2012 07:21 AM, michele caseposta wrote:
 Back again.
 Is there a quick way to add the sample names in the plot?
 I was not able to find anything other than creating a new category with the 
 name in it (and the same color all over).
 
 Hi Michele,
 If by sample names you mean the variable names in your data frame:
 
 library(plotrix)
 mcdat-data.frame(smk=c(No,No,Yes),sex=c(M,M,F),
 age=c(35,24,30))
 sizetree(mcdat,toplab=c(Smoker,Sex,Age),
 col=list(c(gray80,gray20),c(pink,lightblue),rainbow(3)))
 
 This displays the variable names at the top of the stacked bars. If you mean 
 the subject codes, then yes, you would have to create a new variable.
 
 Jim

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


Re: [R] Extracting list names within a looped function

2012-11-15 Thread Ista Zahn
Hi Stan,

On Thu, Nov 15, 2012 at 6:02 AM, Gaj Stan (BIGCAT)
stan@maastrichtuniversity.nl wrote:
 Hello Berend,

 Thanks for your quick response.

 I am aware of the names() function, but this is not the answer to my 
 question, since it will not work within the foo function.

 Let me try to explain it again! (:

 I want to analyze several datasets in a similar fashion and stored all data 
 as seperate list components in a (here: $var1, $var2, $var3). Each component 
 of that list has a unique name and will be sent through the foo()-function 
 using a for-loop. This foo() function would (in my case) generate several 
 plots and output files where I would like to use the name of the component 
 ($var1, $var2 or $var3) in the labels and output file names. I currently am 
 unable to do so.

 As such, my end-goal would be that the foo function returns the name of the 
 list components and not [1] a[[i]], as deparse(substitute(x)) does.

 The output of foo() needs to be:

  [1] var1
  [1] var2
  [1] var3

I suggest iterating over the names themselves, like this:

for(i in names(a)) {
 print(i)
}
[1] var1
[1] var2
[1] var3

If you define your function with two arguments you can do stuff like this:

foo - function(x, d) {
  print(x)
  cat(d[[x]], file=paste(x, .txt, sep=))
  ## other stuff you want to do with d and x
}

for(i in names(a)) {
 foo(x=i, d=a)
}

which is (I think) basically what you are after.

Best,
Ista


 But I'm also happy with
  [1] a[[\var1\]]
  [1] a[[\var2\]]
  [1] a[[\var3\]]
 (or something similar)

 This leads to the question: how can I adjust my foo() so it gives me the 
 output mentioned above?

 I hope that this clears things up.

   -- Stan


 -Original Message-
 From: Berend Hasselman [mailto:b...@xs4all.nl]
 Sent: 15 November 2012 11:27
 To: Gaj Stan (BIGCAT)
 Cc: r-help@r-project.org
 Subject: Re: [R] Extracting list names within a looped function


 On 15-11-2012, at 11:14, Gaj Stan (BIGCAT) wrote:

 Hello all,

 I have the following problem:

 1) A list was defined as 'a'

 a - list(var1=c(100:1), var2=c(1:100), var3=rnorm(100))

 2) a function 'foo' was defined that extracts the variable name assigned to 
 x using the deparse(substitute()) functionality. This name will then be used 
 within the function to generate specific output files, etc.

 foo - function(x) {
  print( deparse(substitute(x)) )
 }

 However, I am currently interested in looping through all list variables and 
 extract the list variable name from within the function. The current loop 
 (see below) will result in

 for(i in 1:length(a)) {
  foo(a[[i]])
 }
 [1] a[[i]]

 which actually does what I expected of deparse(substitute(x)), but is not 
 what I wanted. I would like to end up with something like

 [1] var1
 [1] var2
 [1] var3

 or

 [1] a[[\var1\]]
 [1] a[[\var2\]]
 [1] a[[\var3\]]

 Keep in mind that x has to be a matrix, and not a list. This to keep the 
 function as general as possible.

 Does anyone have any idea on how to tackle this? Is deparse(substitute(x)) 
 here the best way to go? Are there alternatives?

 I'm not sure if I understand what you want but will this give you what you 
 seem to want:

 names(a)

 Berend

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] Can't see what i did wrong..

2012-11-15 Thread Sarah Goslee
Hi Jessica,

Talking may help you, but it's kind of a waste of time for the
thousands of readers of R-help unless you provide a reproducible
example and full context. We'd like to help, but can't without
adequate information.

Sarah

On Thu, Nov 15, 2012 at 9:48 AM, Jessica Streicher
j.streic...@micromata.de wrote:
 Now i let it run for one specific set and got the same bad result, then i 
 deactivated the probabilities and got a good result, then i activated the 
 probabilities again and got a good result .. huh???

 On 15.11.2012, at 15:32, Jessica Streicher wrote:

 Its not scaling.. so..

 I guess i'll stay severely frustrated, and yes i know this is probably not 
 enough information for anyone to help.
 Still, talking helps ;)

 On 15.11.2012, at 15:15, Jessica Streicher wrote:

 with

 pred.pca-predict(splits[[i]]$pca,trainingData@samples)[,1:nPCs]
 dframe-as.data.frame(cbind(pred.pca,class=isExplosive(trainingData,2)));
 results[[i]]$classifier-ksvm(class~.,data=dframe,scaled=T,kernel=polydot,type=C-svc,
  
 C=C,kpar=list(degree=degree,scale=scale,offset=offset),prob.model=T)

 and a degree of 5 i get an error of 0 reported by the ksvm object. But when 
 doing

 pred.pca-predict(splits[[i]]$pca,trainingData@samples)[,1:nPCs]
 pred.svm-kernlab::predict(results[[i]]$classifier,pred.pca,type=probabilities);
 results[[i]]$trainResults$predicted-pred.svm[,2]

 the results vary widely from the class vector. Nearly all predictions are 
 somewhat around 0.29. Its just strange. And i have no idea where things go 
 wrong. They're in the same loop with i, so its probably not an indexing 
 issue.

 Maybe kernlabs predict doesn't scale the data or something?




--
Sarah Goslee
http://www.functionaldiversity.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.


Re: [R] problem in fitting model in NLS function

2012-11-15 Thread U30A J C Nash

Bad scaling will waste a lot of everyone's time.

I put the data in a data frame mdat, then

library(nlmrt)
mdat-read.csv(muzzamil.csv, header=T)
fmn - nlxb(y~a * (x^b), data=mdat, start=c(a=1,b=1), trace=T)
fm - nls(y~a * (x^b), data=mdat, start=c(a=1,b=1), trace=T)
fmn2 - nlxb(y~a2 * ((x-1979)^b2), data=mdat, start=c(a2=1,b2=1), trace=T)
fm2 - nls(y~a2 * ((x-1979)^b2), data=mdat, start=c(a2=1,b2=1), trace=T)

found a possible solution quickly with the last 2 forms. Without 
adjusting the x data, you get a very ill-conditioned problem.


JN



Message: 21
Date: Wed, 14 Nov 2012 03:04:56 -0800 (PST)
From: muzammil786 m.shah...@sheffield.ac.uk
To: r-help@r-project.org
Subject: Re: [R] problem in fitting model in NLS function
Message-ID: 1352891096449-4649473.p...@n4.nabble.com
Content-Type: text/plain; charset=us-ascii

Dear David,

I am having a similar problem on this data (given below). I have tried
several starting values for a and b, but it is consistently giving me:

*fm - nls(y~f(x,a,b), data.frame(x,y), start=c(a=1,b=1))
Error in numericDeriv(form[[3L]], names(ind), env) :
  Missing value or an infinity produced when evaluating the model*

The function f(x,a,b) is defined here:
*f - function(x,a,b) {a * I(x^b)} *

The data is given here:

*  x   y
1  1980   1
2  1981   1
3  1982   1
4  1983   3
5  1984   3
6  1985   5
7  1986   8
8  1987   8
9  1988   9
10 1989  12
11 1990  15
12 1991  24
13 1992  33
14 1993  44
15 1994  62
16 1995  68
17 1996  81
18 1997  87
19 1998 102
20 1999 114
21 2000 123
22 2001 135
23 2002 144
24 2003 158
25 2004 172
26 2005 188
27 2006 197
28 2007 224
29 2008 234
30 2009 254
31 2010 278
32 2011 312
33 2012 317*

I shall be grateful if you could guide me what's wrong here.

Cheers.
Muzammil



--
View this message in context: 
http://r.789695.n4.nabble.com/problem-in-fitting-model-in-NLS-function-tp4345082p4649473.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] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread David Romano
Thanks for the suggestion, Bert; I just re-read the introduction with
particular attention to the sections you mentioned, but I don't see how any
of it bears on my question.  Namely -- to rephrase:  What constraints are
there on the form of the yes and no values required by ifelse?   The
introduction doesn't really speak to this, and the help documentation seems
to suggest that as long the shapes of the test, yes values, and no
values agree, that would be sufficient -- I don't see anything that
specifies that any of these should be of a particular data type.   My
example, however, seems to indicate that the yes and no values can't be
a mixture of characters and numbers, and I'm trying to figure out what the
underlying constraints are on ifelse.

Thanks again,
David

On Thu, Nov 15, 2012 at 6:46 AM, Bert Gunter gunter.ber...@gene.com wrote:

 David:

 You seem to be getting lost in basic R tasks. Have you read the Intro
 to R tutorial? If not, do so, as this should tell you how to do what
 you need. If so, re-read the sections on indexing ([), replacement,
 and NA's. Also read about character vectors and factors.

 -- Bert

 On Thu, Nov 15, 2012 at 3:19 AM, David Romano drom...@stanford.edu
 wrote:
  Hi everyone,
 
  I have a data frame one of whose columns is a character vector and the
 rest
  are numeric, and in debugging a script, I noticed that an ifelse call
 seems
  to be coercing the character column to a numeric column, and producing
  unintended values as a result.   Roughly, here's what I tried to do:
 
  df: a data frame with, say, the first column as a character column and
 the
  second and third columns numeric.
 
  also: NA's occur only in the numeric columns, and if they occur in one,
  they occur in the other as well.
 
  I wanted to replace the NA's in column 2 with 0's and the ones in column
 3
  with 1's, so first I did this:
 
  na.replacements -ifelse(col(df)==2,0,1).
 
  Then I used a second ifelse call to try to remove the NA's as I wanted,
  first by doing this:
 
  clean.df - ifelse(is.na(df), na.replacements, df),
 
  which produced a list of lists vaguely resembling df, with the NA's
 mostly
  intact, and so then I tried this:
 
  clean.df - ifelse(is.na(df), na.replacements, unlist(df)),
 
  which seems to work if all the columns are numeric, but otherwise changes
  strings to numbers.
 
  I can't make sense of the help documentation enough to clear this up, but
  my guess is that the yes and no values passed to ifelse need to be
  vectors, in which case it seems I'll have to use another approach
 entirely,
  but even if is not the case and lists are acceptable, I'm not sure how to
  convert a mixed-mode data frame into a vector-like list of elements
 (which
  I would hope would work).
 
  I'd be grateful for any suggestions!
 
  Thanks,
  David Romano
 
  [[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.



 --

 Bert Gunter
 Genentech Nonclinical Biostatistics

 Internal Contact Info:
 Phone: 467-7374
 Website:

 http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm


[[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] How to modify a S4 function (in the package NADA)

2012-11-15 Thread maxbre
Ok, this is my finally (hopefully) clean session

my.ex-structure(list(TEC = c(0.21, 0.077, 0.06, 0.033, 0.014, 0.0072), LR =
c(FALSE, FALSE, TRUE, FALSE, TRUE, FALSE)), .Names = c(TEC,LR),
row.names = c(NA, -6L), class = data.frame)

library(NADA)

xx-with(my.ex,
 cenfit(TEC,LR)
)

xx

mycenfit - function(x) {
  s = summary(x)
  c(n = nrow(s), n.cen = nrow(s) - sum(s$n.event), median = median(x),
mean = mean(x)[[mean]], sd = sd(x), sum=mean(x)[[mean]]*length(x))
}

mycenfit(xx)


thank you so much for your help
(I still have much to fully understand S4 methods, R objects and functions)

max



--
View this message in context: 
http://r.789695.n4.nabble.com/How-to-modify-a-S4-function-in-the-package-NADA-tp4649586p4649613.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] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread Bert Gunter
David:

You seem to be getting lost in basic R tasks. Have you read the Intro
to R tutorial? If not, do so, as this should tell you how to do what
you need. If so, re-read the sections on indexing ([), replacement,
and NA's. Also read about character vectors and factors.

-- Bert

On Thu, Nov 15, 2012 at 3:19 AM, David Romano drom...@stanford.edu wrote:
 Hi everyone,

 I have a data frame one of whose columns is a character vector and the rest
 are numeric, and in debugging a script, I noticed that an ifelse call seems
 to be coercing the character column to a numeric column, and producing
 unintended values as a result.   Roughly, here's what I tried to do:

 df: a data frame with, say, the first column as a character column and the
 second and third columns numeric.

 also: NA's occur only in the numeric columns, and if they occur in one,
 they occur in the other as well.

 I wanted to replace the NA's in column 2 with 0's and the ones in column 3
 with 1's, so first I did this:

 na.replacements -ifelse(col(df)==2,0,1).

 Then I used a second ifelse call to try to remove the NA's as I wanted,
 first by doing this:

 clean.df - ifelse(is.na(df), na.replacements, df),

 which produced a list of lists vaguely resembling df, with the NA's mostly
 intact, and so then I tried this:

 clean.df - ifelse(is.na(df), na.replacements, unlist(df)),

 which seems to work if all the columns are numeric, but otherwise changes
 strings to numbers.

 I can't make sense of the help documentation enough to clear this up, but
 my guess is that the yes and no values passed to ifelse need to be
 vectors, in which case it seems I'll have to use another approach entirely,
 but even if is not the case and lists are acceptable, I'm not sure how to
 convert a mixed-mode data frame into a vector-like list of elements (which
 I would hope would work).

 I'd be grateful for any suggestions!

 Thanks,
 David Romano

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


Re: [R] GUI Development reg

2012-11-15 Thread Bert Gunter
Vijayan:

Choose one or both from the following.

1. You don't . R is a programming language that you learn. Read the
Intro to R Tutorial to start learning.

2. See the R GUI page on CRAN here: http://www.sciviews.org/_rgui/
 There are several GUI's available for R and you can choose one that
suits.

Cheers,
Bert

On Wed, Nov 14, 2012 at 10:31 PM, Vijayan Padmanabhan
v.padmanab...@itc.in wrote:
 Dear R Group

 I have a character vector from which I want to select a few elements and
 create a new character vector.
 I need a GUI to do this in R Script.
 Can someone help?

 a-c(A,B,C,D,E)

 ## I want to have a GUI  in R that will display elements in object a  as
 a drop down list.. from there I want to be able to select a few elements
 say my requirement is to select A, D and E from the list

 and want to pass the selection into a new vector b, such that

 b-c(A, D , E)

 How do i do this in R?




 Regards
 Vijayan Padmanabhan


 What is expressed without proof can be denied without proof - Euclide.

 Please visit us at www.itcportal.com
 **
 This Communication is for the exclusive use of the intended recipient (s) and 
 shall
 not attach any liability on the originator or ITC Ltd./its Subsidiaries/its 
 Group
 Companies. If you are the addressee, the contents of this email are intended 
 for your use only and it shall not be forwarded to any third party, without 
 first obtaining written authorisation from the originator or ITC Ltd./its 
 Subsidiaries/its Group Companies. It may contain information which is 
 confidential and legally privileged and the same shall not be used or dealt 
 with by any third party in any manner whatsoever without the specific consent 
 of ITC Ltd./its Subsidiaries/its Group Companies.
 [[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.



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


Re: [R] Can't see what i did wrong..

2012-11-15 Thread Jessica Streicher
I'll try .. lets see

 dput(dframe)
structure(list(PC1 = c(-112.131127281872, -116.596689350263, 
-128.974817313418, 1196.74257699487, 1216.80975908625, -162.017759589637, 
-85.3191578683763, -130.528496524968, -6.27985683466795, -110.832877061623, 
-127.466759201992, -106.169095838249, -135.615623230809, -140.740670692038, 
-163.111656805033), PC2 = c(-116.519244989851, 127.45362265627, 
-111.091607020859, -90.5227270764559, -123.103694889442, -92.620202365279, 
-31.3353634789021, -24.4646703348531, 627.701800243656, -5.87156108239855, 
-88.8993352468245, -106.166416491185, -95.3261810128253, -112.315850116593, 
-141.197051597155), PC3 = c(64.9404052536739, 259.296520455491, 
81.2617131909924, -40.2969961195199, -49.959279821408, 114.342573713326, 
-127.625681151677, 293.080433739631, -130.564246301803, 243.838480231849, 
-188.819145619591, -184.73732844957, 68.0106824426824, -202.00600443294, 
-3.31973728306762), PC4 = c(56.5233383519436, -188.28891646169, 
36.982033091297, 2.96535930848599, 38.9643424847775, 66.1927347587241, 
-70.2278717299823, 24.2000870994265, 85.41705362572, 81.3070906919206, 
-49.4076806523943, 44.4291395459566, 44.4189881931216, -47.787706169273, 
60.3084338394971), PC5 = c(-24.4330445432631, 119.03248964697, 
25.3182533898001, 2.22712423872515, 20.1564988015345, 8.58984063196041, 
-73.6618858270628, 154.531152822823, 80.0172481588946, -77.3997650093847, 
12.5317198856102, 16.7807094602606, 21.9728292529402, 18.0679363256966, 
14.8070821345172), PC6 = c(-3.51236160660659, 4.01466215993921, 
-14.0560600152898, 79.9790057450278, 63.8459665084246, 70.1505245709296, 
-9.72399636564978, -37.3441332401865, -20.0211154965333, 34.8148111484049, 
19.6697124222742, -12.5006014423202, -35.9412566332911, 43.8525592643803, 
49.0837309296695), PC7 = c(25.0416790893669, 29.2636829211613, 
58.5827246416567, 24.5865832216293, -3.79787182743163, 32.269692748727, 
9.13653843864113, 22.2828779024266, -1.7405059119, -81.2339879700331, 
-8.39734635571791, 4.90076673663989, 26.3079758222854, -16.6096446464957, 
27.2347172477201), PC8 = c(-7.21492487063905, 41.4415040543379, 
-6.8561527559211, -9.6515803005436, 40.5578239936188, 35.6268320766844, 
4.33982606720149, -27.7334062748555, 1.58916911406888, 42.2854747927154, 
-19.0049848668069, 53.1381176037003, -43.7208819443017, -27.4638912504461, 
26.0693753249626), PC9 = c(5.07013225478207, 3.80978415808406, 
-12.9265139792091, 22.3706065788694, 43.9527567691036, 44.7661368799448, 
-25.6398826082422, 4.37103700086919, -9.0919050870289, 11.9520700564903, 
-23.250383344361, -30.3220249879799, -46.3887501545308, -14.0817576379036, 
16.168581787112), PC10 = c(-17.5630832749372, 52.568055046381, 
-9.07626573878839, -14.0951768936723, -5.23003343696749, 35.0154213026854, 
0.272344896140687, 13.3950601982445, -1.5533667315822, -40.8292771335063, 
-6.65959388343316, 5.06195872128945, -22.7857465669081, 6.62863071798569, 
18.3995069374505), PC11 = c(18.6010453343854, -28.4637751927999, 
1.71806569355502, 46.1205174166346, 9.53199967063977, 41.2972754904467, 
9.33464956019139, 23.3603727930995, 10.9744437554614, -0.126735591637572, 
21.8896623331257, -10.457965922839, -18.8322478793736, 27.7321423838636, 
28.4679654920173), PC12 = c(-2.22649901627144, 2.14317119837832, 
8.11993688993784, -1.02101828008616, -3.02022884335462, 3.99260060747241, 
-3.98208300398649, -8.73435109273014, -15.4116191493509, -21.9916390100063, 
-24.5400095100928, 11.7508407539612, -4.82585090072434, -21.4330004806799, 
4.07445502977139), PC13 = c(12.0478528474097, 19.1463355000476, 
-13.7614159178043, -2.45636501215998, 10.7570602509335, -27.124462677835, 
2.50581414841615, -1.43645727084062, -9.92501401886999, 14.541265924675, 
4.61925247518254, 31.9444025444124, 15.0123077631076, 1.73726777225125, 
-21.7438739224478), PC14 = c(-24.3652304503883, 21.1785358765272, 
0.221058054284211, -28.7788948242716, -0.840491052309543, 40.1941623968201, 
-17.1958234033114, 7.5770624168308, 7.45003285540585, 15.5283651855595, 
-8.65376069406027, 9.56538784228923, 4.23345479961019, -1.50016336971708, 
19.755969304), PC15 = c(9.92727520847547, -16.0078543011331, 
3.37100252722285, 26.8689400893287, 16.2203912046009, -6.07396584265131, 
-7.32119707525572, 0.194098009190007, -10.3216068605436, -23.0845947221256, 
0.696161095884098, -5.29057246485069, -1.79824229741562, -3.26507441975894, 
1.08088312906883), class = c(0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 
0, 0, 0, 0)), .Names = c(PC1, PC2, PC3, PC4, PC5, PC6, 
PC7, PC8, PC9, PC10, PC11, PC12, PC13, PC14, 
PC15, class), row.names = c(2396, 2754, 3645, 7122, 
7106, 7172, 6761, 1599, 2107, 1865, 6795, 6913, 
3329, 6836, 7229), class = data.frame)

These are 15 of my samples, and it seems to work with just that.

classifier-ksvm(class~.,data=dframe,scaled=T,kernel=polydot,type=C-svc,
C=1,kpar=list(degree=5,scale=1,offset=0),prob.model=T)
pred.svm-kernlab::predict(classifier,dframe[,1:15],type=probabilities);


Re: [R] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread arun
Hi,

df1-read.table(text=
col1 col2 col3
A   15.5   8.5
A   8.5    7.5
A   NA NA
B   8.0   6.0
B   NA NA
B   9.0   10.0
,sep=,header=TRUE,stringsAsFactors=FALSE)
 str(df1)
#'data.frame':    6 obs. of  3 variables:
# $ col1: chr  A A A B ...
# $ col2: num  15.5 8.5 NA 8 NA 9
# $ col3: num  8.5 7.5 NA 6 NA 10

 df1$col2[is.na(df1$col2)]-0
 df1$col3[is.na(df1$col3)]-1
 df1
#  col1 col2 col3
#1    A 15.5  8.5
#2    A  8.5  7.5
#3    A  0.0  1.0
#4    B  8.0  6.0
#5    B  0.0  1.0
#6    B  9.0 10.0

#or if you want to use ifelse() from the original df1

 ifelse(is.na(df1$col2),0,df1$col2)
#[1] 15.5  8.5  0.0  8.0  0.0  9.0
 ifelse(is.na(df1$col3),1,df1$col2)
#[1] 15.5  8.5  1.0  8.0  1.0  9.0
A.K.




- Original Message -
From: David Romano drom...@stanford.edu
To: r-help@r-project.org
Cc: 
Sent: Thursday, November 15, 2012 6:19 AM
Subject: [R] using ifelse to remove NA's from specific columns of a data frame 
containing strings and numbers

Hi everyone,

I have a data frame one of whose columns is a character vector and the rest
are numeric, and in debugging a script, I noticed that an ifelse call seems
to be coercing the character column to a numeric column, and producing
unintended values as a result.   Roughly, here's what I tried to do:

df: a data frame with, say, the first column as a character column and the
second and third columns numeric.

also: NA's occur only in the numeric columns, and if they occur in one,
they occur in the other as well.

I wanted to replace the NA's in column 2 with 0's and the ones in column 3
with 1's, so first I did this:

 na.replacements -ifelse(col(df)==2,0,1).

Then I used a second ifelse call to try to remove the NA's as I wanted,
first by doing this:

 clean.df - ifelse(is.na(df), na.replacements, df),

which produced a list of lists vaguely resembling df, with the NA's mostly
intact, and so then I tried this:

 clean.df - ifelse(is.na(df), na.replacements, unlist(df)),

which seems to work if all the columns are numeric, but otherwise changes
strings to numbers.

I can't make sense of the help documentation enough to clear this up, but
my guess is that the yes and no values passed to ifelse need to be
vectors, in which case it seems I'll have to use another approach entirely,
but even if is not the case and lists are acceptable, I'm not sure how to
convert a mixed-mode data frame into a vector-like list of elements (which
I would hope would work).

I'd be grateful for any suggestions!

Thanks,
David Romano

    [[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] Stepwise regression scope: all interacting terms (.^2)

2012-11-15 Thread Mark Ebbert
Dear Gurus,

Thank you in advance for your assistance. I'm trying to understand scope better 
when performing stepwise regression using step. I have a model with a binary 
response variable and 10 predictor variables. When I perform stepwise 
regression I define scope=.^2 to allow interactions between all terms. But I am 
missing something. When I perform stepwise regression (both directions) on the 
main model (y~x1+x2+…+x10) the method returns quickly with an answer; however, 
when I define all interactions in the main model (y~x1+x2+…+x10+x1:x2+x1:x3+…) 
and then perform stepwise regression (backward only) it runs so long I have to 
kill it. 

So here's my question: what is the difference between scope=.^2 on the additive 
(proper term?) model and defining all interactions and doing backward 
regression? My understanding is that .^2 is supposed to allow all interactions!

Thank you for your help.

Mark

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Confidence intervals in Ripley's K function - a little challenge...

2012-11-15 Thread AMFTom
Sorry - CSR = Complete Spatial Randomness. 



--
View this message in context: 
http://r.789695.n4.nabble.com/Confidence-intervals-in-Ripley-s-K-function-a-little-challenge-tp4649392p4649597.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] finding the lowest which is not an outlier

2012-11-15 Thread przemek
Hello,

If I have a series of numbers, and I want to find the level (the lowest
value) on which each series is becam significant in the meaning of of
frequency. In other words, how to find the value of lowest point (number)
which is not an outlier? 

Thanks in advance

Przemek



--
View this message in context: 
http://r.789695.n4.nabble.com/finding-the-lowest-which-is-not-an-outlier-tp4649595.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] merge dataframes with condition

2012-11-15 Thread Geophagus
Hi @ all,
I wamnt to combine two dataframes including a condition.
I have  two dataframes like the following:

animal-c(bear,bear,lion,monkey,fish,monkey,bear,zebra,zebra)
val-c(2,42,67,5,12,9,87,1,12)
place-c(S,N,N,Z,R,O,E,I,Q)
df1-data.frame(animal,val,place)
animal-c(bear,bear,lion,monkey,fish,monkey,bear,zebra,zebra)
val-c(21,45,78,6,18,77,89,17,28)
place-c(S,N,N,Z,R,G,O,P,Q)
df2-data.frame(animal,val,place)

I would like to merge them with a condition. If animal and place are
eqal in both df's, then add the values.
If not add all three parameters (animal,value,place) at the bottom
(like rbind).

I hope somebody can help me.
Thank a lot.
geo




--
View this message in context: 
http://r.789695.n4.nabble.com/merge-dataframes-with-condition-tp4649605.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] Importing Data for a two sample t-test

2012-11-15 Thread arun
HI,
If you need to separate into two datasets,


 dat1[dat1$company==A,]
#  weights company
#1   1   A
#2   2   A
#or

 dat1[dat1$company==B,]

#or split into a list
 split(dat1,dat1$company)



A.K.



- Original Message -
From: nilsonern nilson...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Wednesday, November 14, 2012 11:52 PM
Subject: [R] Importing Data for a two sample t-test

I am trying to do a two sample t-test with data that i received in a text
document.  one list has the slab weights and the second has the company it
is associated with.  here is an example.

weights  company
1                  A
2                  A  
2                  B
3                  B

I was able to import the data but i cannot figure out how separate the data. 
I want to put them in two separate sets, one being A and one being B.  Any
help would be appreciated.  Thanks.



--
View this message in context: 
http://r.789695.n4.nabble.com/Importing-Data-for-a-two-sample-t-test-tp4649565.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] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread Stendera, Sonja, Dr.
Hi everyone, please put me off that list!!! The unsubscribe function does not 
function...
THANKS!!!
BW Sonja

-Ursprüngliche Nachricht-
Von: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] Im 
Auftrag von David Romano
Gesendet: 15 November 2012 12:19
An: r-help@r-project.org
Betreff: [R] using ifelse to remove NA's from specific columns of a data frame 
containing strings and numbers

Hi everyone,

I have a data frame one of whose columns is a character vector and the rest are 
numeric, and in debugging a script, I noticed that an ifelse call seems to be 
coercing the character column to a numeric column, and producing
unintended values as a result.   Roughly, here's what I tried to do:

df: a data frame with, say, the first column as a character column and the 
second and third columns numeric.

also: NA's occur only in the numeric columns, and if they occur in one, they 
occur in the other as well.

I wanted to replace the NA's in column 2 with 0's and the ones in column 3 with 
1's, so first I did this:

 na.replacements -ifelse(col(df)==2,0,1).

Then I used a second ifelse call to try to remove the NA's as I wanted, first 
by doing this:

 clean.df - ifelse(is.na(df), na.replacements, df),

which produced a list of lists vaguely resembling df, with the NA's mostly 
intact, and so then I tried this:

 clean.df - ifelse(is.na(df), na.replacements, unlist(df)),

which seems to work if all the columns are numeric, but otherwise changes 
strings to numbers.

I can't make sense of the help documentation enough to clear this up, but my 
guess is that the yes and no values passed to ifelse need to be vectors, in 
which case it seems I'll have to use another approach entirely, but even if is 
not the case and lists are acceptable, I'm not sure how to convert a mixed-mode 
data frame into a vector-like list of elements (which I would hope would work).

I'd be grateful for any suggestions!

Thanks,
David Romano

[[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] Adding two different factors to one observation?

2012-11-15 Thread Florian Ahrweiler
In a data frame, I would like to assign two or more factors to one 
observation. Is it possible? If so, how?


Example: In the variable $ dishes, there are several levels: cup, 
plate, saucer. In my first observation, I see a saucer only. But in 
the second one, I see a cup and a saucer.  In the third, however, there 
is only a cup, in the fourth a plate only and so forth.


I'm an R beginner and I'll be grateful for any help.

Florian

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] RMySQL install on windows

2012-11-15 Thread Gabor Grothendieck
On Thu, Nov 15, 2012 at 7:49 AM, sbarandiaran sbaran...@gmail.com wrote:
 Uwe, I set the variable with single backslashes, but the output remains the
 same. The last part reads:

 gcc -m64 -shared -s -static-libgcc -o RMySQL.dll tmp.def RS-DBI.o
 RS-MySQL.o C:\Program Files\MySQL\MySQL Server 5.5/bin/libmysql.dll
 -Ld:/RCompile/CRANpkg/extralibs64/local/lib/x64
 -Ld:/Rcompile/CRANpkg/extralibs64/local/lib
 -LC:/PROGRA~1/R/R-215~1.1/BIN/X64 -lR
 gcc.exe: error:  C:\Program Files\MySQL\MySQL Server 5.5/bin/libmySQL.dll:
 No such file or directory
 ERROR: compilation failed for package 'RMySQL'
 * removing 'C:/Users/Acer/Documents/R/win-library/2.15/RMySQL' 


The error message says it can't find a particular file.  You may have
an incomplete installation or perhaps in your distribution the file is
not in the expected place.  First look for it:

cd %MYSQL_HOME%
dir/s/b libmySQL.dll

If its missing then there is a problem with your installation of MySQL.

If its in a different location than expected copy it to the expected
location. Do that as Administrator:

copy ...wherever...\libmySQL.dll %MYSQL_HOME%\bin

If it happens again with some other file then copy it too.

--
Statistics  Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.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] Installing R on Ubuntu

2012-11-15 Thread Karel van Duijvenboden
Hello R-help team,

I seek your help (for what is most likely a very simple problem). I'm new
to Ubuntu and tried to install R using the Ubuntu Software Center. However,
after clicking the install command, I always get prompted with the error 
Failed to download package files --- check your internet connection.
Details: Failed to fetch
http://archive.ubuntu.com/ubuntu/pool/main/a/apparmor/dh-apparmor_2.7.102-0ubuntu3.1_all.deb404
 Not Found [IP: 91.189.92.200 80]

However, my internet connection is perfectly fine and I've already
installed a bunch of programs using the Software Center without any
problems. I've tried various of the available R packages (also the
Rcommander) and always get this same error. Perhaps it has something to do
with the server/mirror?

Alternatively, I've downloaded a .zip of the package, but so far I've
failed to install the program. With me, for now, being an unequivocal
Ubuntu dummy I would prefer the straightforward Software Center route and
in any case I wonder why it does not work for me.

Best regards and thanks in advance!

Karel van Duijvenboden (Netherlands)

[[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] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread William Dunlap
Replace your NA's column by column, not all at once. 

In your first example, of the form
ifelse(condition, numbers, data.frame) 
the second and third arguments are replicated to the length
of the first.  A data.frame's length is the number of columns
it has, so ifelse repeats its columns, not what you want.
Also, the 2nd and 3rd arguments to ifelse should be of the same
type, since the output will be a vector that accepts some values
from each.  If they don't have the same type the output will be
of some type that can accept values from both types.  That type
is often character or list, not what you want

Your second example code used unlist(data.frame).  data.frames
contain columns of various classes and unlist(data.frame) creates
a vector with one class, the class is chosen to retain the information,
if not the format, of columns in the data.frame.  It is generally not
a useful thing, unless all columns have the same class.

You showed some code but not data, so I'll make up something like
you described
   df - data.frame(stringsAsFactors=FALSE,
 Number1 = c(1, 2, 3, NA, 5, 6),
 Number2 = c(11, 12, 13, 14, 14, NA),
 String = c(one,two,NA,four,five,six),
 Factor = factor(c(Group A, NA, Group A, Group B, Group B, 
Group B))) 
Look at its structure with
str(df)
   'data.frame':   6 obs. of  4 variables:
$ Number1: num  1 2 3 NA 5 6
$ Number2: num  11 12 13 14 14 NA
$ String : chr  one two NA four ...
$ Factor : Factor w/ 2 levels Group A,Group B: 1 NA 1 2 2 2
To do the sort of conversion you want try something like
f - function(d) {
for(i in seq_along(d)) {
di - d[[i]]
di[is.na(di)] - if (is.numeric(di)) { # could use switch instead 
of if-then-else 
  if (i==2) { 0 } else { 1 }
  } else if (is.factor(di)) {
  levels(di)[1] # I don't know what 
you want here
   } else if (is.character(di)) {
  Unknown
   }
   d[[i]] - di
}
d
}
That would give you
str(f(df))
  'data.frame':   6 obs. of  4 variables:
   $ Number1: num  1 2 3 1 5 6
   $ Number2: num  11 12 13 14 14 0
   $ String : chr  one two Unknown four ...
   $ Factor : Factor w/ 2 levels Group A,Group B: 1 1 1 2 2 2

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com

 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of David Romano
 Sent: Thursday, November 15, 2012 7:58 AM
 To: Bert Gunter
 Cc: r-help@r-project.org
 Subject: Re: [R] using ifelse to remove NA's from specific columns of a data 
 frame
 containing strings and numbers
 
 Thanks for the suggestion, Bert; I just re-read the introduction with
 particular attention to the sections you mentioned, but I don't see how any
 of it bears on my question.  Namely -- to rephrase:  What constraints are
 there on the form of the yes and no values required by ifelse?   The
 introduction doesn't really speak to this, and the help documentation seems
 to suggest that as long the shapes of the test, yes values, and no
 values agree, that would be sufficient -- I don't see anything that
 specifies that any of these should be of a particular data type.   My
 example, however, seems to indicate that the yes and no values can't be
 a mixture of characters and numbers, and I'm trying to figure out what the
 underlying constraints are on ifelse.
 
 Thanks again,
 David
 
 On Thu, Nov 15, 2012 at 6:46 AM, Bert Gunter gunter.ber...@gene.com wrote:
 
  David:
 
  You seem to be getting lost in basic R tasks. Have you read the Intro
  to R tutorial? If not, do so, as this should tell you how to do what
  you need. If so, re-read the sections on indexing ([), replacement,
  and NA's. Also read about character vectors and factors.
 
  -- Bert
 
  On Thu, Nov 15, 2012 at 3:19 AM, David Romano drom...@stanford.edu
  wrote:
   Hi everyone,
  
   I have a data frame one of whose columns is a character vector and the
  rest
   are numeric, and in debugging a script, I noticed that an ifelse call
  seems
   to be coercing the character column to a numeric column, and producing
   unintended values as a result.   Roughly, here's what I tried to do:
  
   df: a data frame with, say, the first column as a character column and
  the
   second and third columns numeric.
  
   also: NA's occur only in the numeric columns, and if they occur in one,
   they occur in the other as well.
  
   I wanted to replace the NA's in column 2 with 0's and the ones in column
  3
   with 1's, so first I did this:
  
   na.replacements -ifelse(col(df)==2,0,1).
  
   Then I used a second ifelse call to try to remove the NA's as I wanted,
   first by doing this:
  
   clean.df - ifelse(is.na(df), na.replacements, df),
  
   

Re: [R] Can't see what i did wrong..

2012-11-15 Thread Jessica Streicher
Guess it has something t do with the values in prob.model. The classifiers with 
bad predicitons have positive values and the ones with good predictions have 
negative values.

On 15.11.2012, at 17:18, Jessica Streicher wrote:

 I'll try .. lets see
 
 dput(dframe)
 structure(list(PC1 = c(-112.131127281872, -116.596689350263, 
 -128.974817313418, 1196.74257699487, 1216.80975908625, -162.017759589637, 
 -85.3191578683763, -130.528496524968, -6.27985683466795, -110.832877061623, 
 -127.466759201992, -106.169095838249, -135.615623230809, -140.740670692038, 
 -163.111656805033), PC2 = c(-116.519244989851, 127.45362265627, 
 -111.091607020859, -90.5227270764559, -123.103694889442, -92.620202365279, 
 -31.3353634789021, -24.4646703348531, 627.701800243656, -5.87156108239855, 
 -88.8993352468245, -106.166416491185, -95.3261810128253, -112.315850116593, 
 -141.197051597155), PC3 = c(64.9404052536739, 259.296520455491, 
 81.2617131909924, -40.2969961195199, -49.959279821408, 114.342573713326, 
 -127.625681151677, 293.080433739631, -130.564246301803, 243.838480231849, 
 -188.819145619591, -184.73732844957, 68.0106824426824, -202.00600443294, 
 -3.31973728306762), PC4 = c(56.5233383519436, -188.28891646169, 
 36.982033091297, 2.96535930848599, 38.9643424847775, 66.1927347587241, 
 -70.2278717299823, 24.2000870994265, 85.41705362572, 81.3070906919206, 
 -49.4076806523943, 44.4291395459566, 44.4189881931216, -47.787706169273, 
 60.3084338394971), PC5 = c(-24.4330445432631, 119.03248964697, 
 25.3182533898001, 2.22712423872515, 20.1564988015345, 8.58984063196041, 
 -73.6618858270628, 154.531152822823, 80.0172481588946, -77.3997650093847, 
 12.5317198856102, 16.7807094602606, 21.9728292529402, 18.0679363256966, 
 14.8070821345172), PC6 = c(-3.51236160660659, 4.01466215993921, 
 -14.0560600152898, 79.9790057450278, 63.8459665084246, 70.1505245709296, 
 -9.72399636564978, -37.3441332401865, -20.0211154965333, 34.8148111484049, 
 19.6697124222742, -12.5006014423202, -35.9412566332911, 43.8525592643803, 
 49.0837309296695), PC7 = c(25.0416790893669, 29.2636829211613, 
 58.5827246416567, 24.5865832216293, -3.79787182743163, 32.269692748727, 
 9.13653843864113, 22.2828779024266, -1.7405059119, -81.2339879700331, 
 -8.39734635571791, 4.90076673663989, 26.3079758222854, -16.6096446464957, 
 27.2347172477201), PC8 = c(-7.21492487063905, 41.4415040543379, 
 -6.8561527559211, -9.6515803005436, 40.5578239936188, 35.6268320766844, 
 4.33982606720149, -27.7334062748555, 1.58916911406888, 42.2854747927154, 
 -19.0049848668069, 53.1381176037003, -43.7208819443017, -27.4638912504461, 
 26.0693753249626), PC9 = c(5.07013225478207, 3.80978415808406, 
 -12.9265139792091, 22.3706065788694, 43.9527567691036, 44.7661368799448, 
 -25.6398826082422, 4.37103700086919, -9.0919050870289, 11.9520700564903, 
 -23.250383344361, -30.3220249879799, -46.3887501545308, -14.0817576379036, 
 16.168581787112), PC10 = c(-17.5630832749372, 52.568055046381, 
 -9.07626573878839, -14.0951768936723, -5.23003343696749, 35.0154213026854, 
 0.272344896140687, 13.3950601982445, -1.5533667315822, -40.8292771335063, 
 -6.65959388343316, 5.06195872128945, -22.7857465669081, 6.62863071798569, 
 18.3995069374505), PC11 = c(18.6010453343854, -28.4637751927999, 
 1.71806569355502, 46.1205174166346, 9.53199967063977, 41.2972754904467, 
 9.33464956019139, 23.3603727930995, 10.9744437554614, -0.126735591637572, 
 21.8896623331257, -10.457965922839, -18.8322478793736, 27.7321423838636, 
 28.4679654920173), PC12 = c(-2.22649901627144, 2.14317119837832, 
 8.11993688993784, -1.02101828008616, -3.02022884335462, 3.99260060747241, 
 -3.98208300398649, -8.73435109273014, -15.4116191493509, -21.9916390100063, 
 -24.5400095100928, 11.7508407539612, -4.82585090072434, -21.4330004806799, 
 4.07445502977139), PC13 = c(12.0478528474097, 19.1463355000476, 
 -13.7614159178043, -2.45636501215998, 10.7570602509335, -27.124462677835, 
 2.50581414841615, -1.43645727084062, -9.92501401886999, 14.541265924675, 
 4.61925247518254, 31.9444025444124, 15.0123077631076, 1.73726777225125, 
 -21.7438739224478), PC14 = c(-24.3652304503883, 21.1785358765272, 
 0.221058054284211, -28.7788948242716, -0.840491052309543, 40.1941623968201, 
 -17.1958234033114, 7.5770624168308, 7.45003285540585, 15.5283651855595, 
 -8.65376069406027, 9.56538784228923, 4.23345479961019, -1.50016336971708, 
 19.755969304), PC15 = c(9.92727520847547, -16.0078543011331, 
 3.37100252722285, 26.8689400893287, 16.2203912046009, -6.07396584265131, 
 -7.32119707525572, 0.194098009190007, -10.3216068605436, -23.0845947221256, 
 0.696161095884098, -5.29057246485069, -1.79824229741562, -3.26507441975894, 
 1.08088312906883), class = c(0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 
 0, 0, 0, 0)), .Names = c(PC1, PC2, PC3, PC4, PC5, PC6, 
 PC7, PC8, PC9, PC10, PC11, PC12, PC13, PC14, 
 PC15, class), row.names = c(2396, 2754, 3645, 7122, 
 7106, 7172, 6761, 1599, 2107, 1865, 6795, 6913, 
 3329, 6836, 7229), class = data.frame)
 
 These are 15 of my 

Re: [R] merge dataframes with condition

2012-11-15 Thread jim holtman
Is this what you want:

 animal-c(bear,bear,lion,monkey,fish,monkey,bear,zebra,zebra)
 val-c(2,42,67,5,12,9,87,1,12)
 place-c(S,N,N,Z,R,O,E,I,Q)
 df1-data.frame(animal,val,place)
 animal-c(bear,bear,lion,monkey,fish,monkey,bear,zebra,zebra)
 val-c(21,45,78,6,18,77,89,17,28)
 place-c(S,N,N,Z,R,G,O,P,Q)
 df2-data.frame(animal,val,place)
 x - merge(df1, df2, by = c('animal', 'place'), all = TRUE)
 # compute the total
 x$value - x$val.x + x$val.y
 # separate the full/partial matches
 x[order(is.na(x$value)), ]
   animal place val.x val.y value
2bear N424587
4bear S 22123
5fish R121830
6lion N6778   145
8  monkey Z 5 611
11  zebra Q122840
1bear E87NANA
3bear ONA89NA
7  monkey O 9NANA
9  monkey GNA77NA
10  zebra I 1NANA
12  zebra PNA17NA


On Thu, Nov 15, 2012 at 9:47 AM, Geophagus f...@retposto.net wrote:
 Hi @ all,
 I wamnt to combine two dataframes including a condition.
 I have  two dataframes like the following:

 animal-c(bear,bear,lion,monkey,fish,monkey,bear,zebra,zebra)
 val-c(2,42,67,5,12,9,87,1,12)
 place-c(S,N,N,Z,R,O,E,I,Q)
 df1-data.frame(animal,val,place)
 animal-c(bear,bear,lion,monkey,fish,monkey,bear,zebra,zebra)
 val-c(21,45,78,6,18,77,89,17,28)
 place-c(S,N,N,Z,R,G,O,P,Q)
 df2-data.frame(animal,val,place)

 I would like to merge them with a condition. If animal and place are
 eqal in both df's, then add the values.
 If not add all three parameters (animal,value,place) at the bottom
 (like rbind).

 I hope somebody can help me.
 Thank a lot.
 geo




 --
 View this message in context: 
 http://r.789695.n4.nabble.com/merge-dataframes-with-condition-tp4649605.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
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Compraring two independent samples

2012-11-15 Thread David Arnold
Hi,

In my reading of pairing means of two independent samples, I read statements
such as the standard error of the meanof X1 minus the mean of X2 is the
square root of s1^2/n1+s2^2/n2. Then I read:

We could now derive the two independent samples confidence interval and
test statistic. However, a problem arises in that the distribution of the
test statistic (under the null hypothesis) will not be a t-distribution.

I keep seeing this type of thing stated in a variety of readings but I never
seem to get an explanation. This is just stated and the author goes on to an
alternate approach.

So, I am wondering if there is some sort of R simulation that could be used
to demonstrate that this distribution is not a t-distribution.

David



--
View this message in context: 
http://r.789695.n4.nabble.com/Compraring-two-independent-samples-tp4649636.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] Importing Data for a two sample t-test

2012-11-15 Thread Peter Ehlers

On 2012-11-14 20:52, nilsonern wrote:

I am trying to do a two sample t-test with data that i received in a text
document.  one list has the slab weights and the second has the company it
is associated with.  here is an example.

weights  company
1  A
2  A
2  B
3  B

I was able to import the data but i cannot figure out how separate the data.
I want to put them in two separate sets, one being A and one being B.  Any
help would be appreciated.  Thanks.



Why separate? The 'long' form is generally preferred in
statistical analyses.
Just use the formula version of t.test().

Peter Ehlers




--
View this message in context: 
http://r.789695.n4.nabble.com/Importing-Data-for-a-two-sample-t-test-tp4649565.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] Compraring two independent samples

2012-11-15 Thread Peter Ehlers

On 2012-11-15 10:17, David Arnold wrote:

Hi,

In my reading of pairing means of two independent samples, I read statements
such as the standard error of the meanof X1 minus the mean of X2 is the
square root of s1^2/n1+s2^2/n2. Then I read:

We could now derive the two independent samples confidence interval and
test statistic. However, a problem arises in that the distribution of the
test statistic (under the null hypothesis) will not be a t-distribution.

I keep seeing this type of thing stated in a variety of readings but I never
seem to get an explanation. This is just stated and the author goes on to an
alternate approach.

So, I am wondering if there is some sort of R simulation that could be used
to demonstrate that this distribution is not a t-distribution.

David


If the populations are Normal, see Wikipedia (or elsewhere) for the
Behrens–Fisher problem. If the populations are not Normal, I don't
see why a t-distribution would be expected.

I seem to recall that Welch included some simulation results in his
Biometrika paper (1947? 1953?; I'm getting senile). Shouldn't be
difficult to generate in R. Maybe Greg Snow's TeachingDemos package
has something.

Peter Ehlers





--
View this message in context: 
http://r.789695.n4.nabble.com/Compraring-two-independent-samples-tp4649636.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] how to view source code of a function inside a package?

2012-11-15 Thread C W
Dear list,
I am trying to look at the function inside a package.  I know that
methods() would do the trick, but what if the function is hidden?  I have a
problem displaying the hidden function.

Say, for example the MCMC package.  How do you view the code of that
function?

something like this:

 which

function (x, arr.ind = FALSE, useNames = TRUE)

{

wh - .Internal(which(x))

if (arr.ind  !is.null(d - dim(x)))

arrayInd(wh, d, dimnames(x), useNames = useNames)

else wh

}

bytecode: 0x1021eef50

environment: namespace:base

[[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] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread soon yi
#Data
df-data.frame(id=letters[1:10],var1=rnorm(10,10,5),var2=rnorm(10,5,2),var3=rnorm(10,1,1))
#Missing
df$var1[2]-df$var2[c(2,6)]-df$var3[c(2,5)]-NA

na.replace-seq(1:ncol(df))-1

df[,names(df)]-sapply(1:dim(df)[2], function(ii)
{ifelse(is.na(df[,ii]),na.replace[ii],df[,ii])} )




David Romano-2 wrote
 Hi everyone,
 
 I have a data frame one of whose columns is a character vector and the
 rest
 are numeric, and in debugging a script, I noticed that an ifelse call
 seems
 to be coercing the character column to a numeric column, and producing
 unintended values as a result.   Roughly, here's what I tried to do:
 
 df: a data frame with, say, the first column as a character column and the
 second and third columns numeric.
 
 also: NA's occur only in the numeric columns, and if they occur in one,
 they occur in the other as well.
 
 I wanted to replace the NA's in column 2 with 0's and the ones in column 3
 with 1's, so first I did this:
 
 na.replacements -ifelse(col(df)==2,0,1).
 
 Then I used a second ifelse call to try to remove the NA's as I wanted,
 first by doing this:
 
 clean.df - ifelse(is.na(df), na.replacements, df),
 
 which produced a list of lists vaguely resembling df, with the NA's mostly
 intact, and so then I tried this:
 
 clean.df - ifelse(is.na(df), na.replacements, unlist(df)),
 
 which seems to work if all the columns are numeric, but otherwise changes
 strings to numbers.
 
 I can't make sense of the help documentation enough to clear this up, but
 my guess is that the yes and no values passed to ifelse need to be
 vectors, in which case it seems I'll have to use another approach
 entirely,
 but even if is not the case and lists are acceptable, I'm not sure how to
 convert a mixed-mode data frame into a vector-like list of elements (which
 I would hope would work).
 
 I'd be grateful for any suggestions!
 
 Thanks,
 David Romano
 
   [[alternative HTML version deleted]]
 
 __

 R-help@

  mailing list
 https://stat.ethz.ch/mailman/listinfo/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 this message in context: 
http://r.789695.n4.nabble.com/using-ifelse-to-remove-NA-s-from-specific-columns-of-a-data-frame-containing-strings-and-numbers-tp4649599p4649642.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] how to view source code of a function inside a package?

2012-11-15 Thread Duncan Murdoch

On 15/11/2012 2:21 PM, C W wrote:

Dear list,
I am trying to look at the function inside a package.  I know that
methods() would do the trick, but what if the function is hidden?  I have a
problem displaying the hidden function.

Say, for example the MCMC package.  How do you view the code of that
function?


You can use the prefix MCMC:::foo to display the foo function from MCMC, 
whether or not it is exported.


Duncan Murdoch



something like this:

 which

function (x, arr.ind = FALSE, useNames = TRUE)

{

 wh - .Internal(which(x))

 if (arr.ind  !is.null(d - dim(x)))

 arrayInd(wh, d, dimnames(x), useNames = useNames)

 else wh

}

bytecode: 0x1021eef50

environment: namespace:base

[[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] how to view source code of a function inside a package?

2012-11-15 Thread Sarah Goslee
This is R FAQ 7.40, and that document gives some good pointers:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-do-I-access-the-source-code-for-a-function_003f

I prefer to simply download the source code version of the package
from CRAN, so that comments aren't stripped, but there are several
other options.

Sarah

On Thu, Nov 15, 2012 at 2:21 PM, C W tmrs...@gmail.com wrote:
 Dear list,
 I am trying to look at the function inside a package.  I know that
 methods() would do the trick, but what if the function is hidden?  I have a
 problem displaying the hidden function.

 Say, for example the MCMC package.  How do you view the code of that
 function?

 something like this:

 which

 function (x, arr.ind = FALSE, useNames = TRUE)

 {

 wh - .Internal(which(x))

 if (arr.ind  !is.null(d - dim(x)))

 arrayInd(wh, d, dimnames(x), useNames = useNames)

 else wh

 }

 bytecode: 0x1021eef50

 environment: namespace:base


--
Sarah Goslee
http://www.functionaldiversity.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.


Re: [R] Optimizing

2012-11-15 Thread Sam Asin
Hey,

It's actually not homework, what gave you that impression?  I graduated in
May and studied Math, economics, and international relations, so I don't
have much of a programming background.  This is a project that I'm working
on out of personal interest.

Obviously, I've tried doing some homework, but after 45 minutes of digging
around without even really having any leads I figured I would post here.

The optimization problems I see more generally seem tailored towards
maximizing a function subject to some constraint on that function.  For
example, maximizing U(x,y)=2x^2+4y s.t. x+y=3.  I don't really see a way to
frame my current maximization like that at all.  We aren't choosing one
observation in our dataset, we are choosing a group.  And, the constraints
aren't something like the types sum to a number, but rather that our choice
of observations meet some specific condition.

Sorry if I'm being clueless here, but when I look at
http://cran.r-project.org/web/views/Optimization.html I just see a giant
list of packages, most of which I believe are optimizing a function subject
to constraints.  Maybe my problem actually is a common one, there is some
package out there that would do it, and I just need to find it.  If so, my
googling and looking on the help pages has been so far unsuccessful. I
apologize if the answer really is sitting there on some help page, but I
really haven't found it.  If this were some homework problem, then I would
know that it's probably a common, normal thing, and feel more confident
looking on the Cran page.  But, since it isn't, I wasn't even sure if the
answer was out there and my searching had so far been fruitless.  That's
why I wanted to know if there would be some function that would do this
sort of thing or if it's the sort of thing that I just need to manually
work through.

The help pages are over my head in so far as the help pages are highly
technical and focused on methods.  They assume a knowledge about the basic
type of optimization problem that I don't have, and I think that's because
there is a standard type of optimization that is most common.

Anyways, I am thinking I might just try to manually do the calculation
because I can't follow the optimize commands.  The general strategy I think
is to somehow make a dataset that has all combinations of 6 people as rows.
 Then, for each row, make a vector that is just all the types of the people
in that row, a vector for the sum of the values, and a vector for the sum
of the wages.  Then, keep only those rows which have the correct types and
wages under the max.  Then, sort by the sum of the values.  Let me know if
you have any better ideas!

Sam


On Wed, Nov 14, 2012 at 7:35 PM, Bert Gunter gunter.ber...@gene.com wrote:

 Sam:

 1. Homework? R has a no homework policy.

 2. But in any case, check out the Optimization task view on CRAN. You
 should be able to find something there that meets your needs.

 Of course, if something is a little over your head, that's not an
 excuse, but rather an admission that you have to do some homework on
 your own.

 Cheers,
 Bert

 On Wed, Nov 14, 2012 at 5:23 PM, Sam Asin asin@gmail.com wrote:
  Hello,
 
  I am fairly new with R and am having trouble finding an optimal group.  I
  checked the help functions for the various optimize commands and it was a
  little over my head.
 
  I have a dataset with 4 columns, name, type, value, and cost.  The set
  consists of a list of people, which have 3 types.  I want to choose 6
  people, two of each type, and maximize the sum of their values.  However,
  I'm subject to the constraint that the wage of the three people has to
 sum
  to less than 20 dollars.  Here is some sample data.
 
  people - c(A, B, C, D, E, F, G, H, I)
  type- c(1, 1, 1, 1, 2, 2, 3, 3, 3)
  value-c(25.20, 24, 38, 20, 14, 20, 31, 11, 8)
  wage- c(4, 3.8, 5.1, 3.5, 2.4, 3, 6, 2.4, 2)
 
  data- data.frame(people, type, value, wage)
 
  With this small dataset the question isn't very interesting, but the
 answer
  would be something like person C, D, E, F, G, and I (I didn't check to
 see
  that those prices sum to less than $20).
 
  How can I write a program that will do this?  Can I just use the optimize
  command?  Do I have to transform my dataset into something that is easier
  to use the optimize command on?  Or should I write my own code that does
  the process?
 
  Thanks,
 
  Sam
 
  [[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.



 --

 Bert Gunter
 Genentech Nonclinical Biostatistics

 Internal Contact Info:
 Phone: 467-7374
 Website:

 http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm


[[alternative HTML version 

Re: [R] Adding two different factors to one observation?

2012-11-15 Thread Jean V Adams
Florian,

There are a number of different ways to handle data like this.  Two that 
come to my mind are shown below.  You could allow each observation to be 
represented by multiple rows in the data frame:

   obs dishes
11 saucer
22cup
32  plate
42 saucer
53cup
63  plate
74cup
84 saucer
96  plate
10   6 saucer
11   7  plate
12   8cup

Or you could let each level be its own variable:

  obs cup plate saucer
1   1   0 0  1
2   2   1 1  1
3   3   1 1  0
4   4   1 0  1
5   5   0 0  0
6   6   0 1  1
7   7   0 1  0
8   8   1 0  0

The arrangement that you choose will likely depend on what you want to do 
with the data.

Jean



Florian Ahrweiler florian.ahrwei...@uni-wh.de wrote on 11/15/2012 
10:10:53 AM:
 
 In a data frame, I would like to assign two or more factors to one 
 observation. Is it possible? If so, how?
 
 Example: In the variable $ dishes, there are several levels: cup, 
 plate, saucer. In my first observation, I see a saucer only. But in 
 the second one, I see a cup and a saucer.  In the third, however, there 
 is only a cup, in the fourth a plate only and so forth.
 
 I'm an R beginner and I'll be grateful for any help.
 
 Florian

[[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] Can you have a by variable in Lag function as in SAS

2012-11-15 Thread ramoss
Hello,

I want to use lag on a time variable but I have to take date into
consideration ie I don't want days to overlap ie: 
I don't want my first time of today to match my last time of yeterday.

In SAS I would use :

data x;
  set y;
  by date tim;
  previous=lag(tim);
  if first.date then
 do;
previous=.;
 end;
run;

How can I do something similar in R?  I can't find any examples anywhere.

Thank you all for your help.



--
View this message in context: 
http://r.789695.n4.nabble.com/Can-you-have-a-by-variable-in-Lag-function-as-in-SAS-tp4649647.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] how to view source code of a function inside a package?

2012-11-15 Thread C W
thanks all.  The mcmc:::foo is exactly what I am looking for.

On Thu, Nov 15, 2012 at 2:35 PM, Duncan Murdoch murdoch.dun...@gmail.comwrote:

 On 15/11/2012 2:21 PM, C W wrote:

 Dear list,
 I am trying to look at the function inside a package.  I know that
 methods() would do the trick, but what if the function is hidden?  I have
 a
 problem displaying the hidden function.

 Say, for example the MCMC package.  How do you view the code of that
 function?


 You can use the prefix MCMC:::foo to display the foo function from MCMC,
 whether or not it is exported.

 Duncan Murdoch


 something like this:

  which

 function (x, arr.ind = FALSE, useNames = TRUE)

 {

  wh - .Internal(which(x))

  if (arr.ind  !is.null(d - dim(x)))

  arrayInd(wh, d, dimnames(x), useNames = useNames)

  else wh

 }

 bytecode: 0x1021eef50

 environment: namespace:base

 [[alternative HTML version deleted]]

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




[[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] combine similar variables in chart

2012-11-15 Thread Jean V Adams
You've included three I wants in your message, but no question.

Are you looking for functions?  Try searching ... in R, on google, on 
http://rseek.org/, ...

Have you tried some code, but can't get it to work?  Send your code with 
error messages, and tell us precisely what you trying to get your code to 
do.

Did you want us to do your homework?  Good luck with that.

Jean



Marcella m.e.j.meerk...@students.uu.nl wrote on 11/15/2012 04:36:56 AM:

 
 I want to make a chart on variables which are taken in 2 different years 
on 2
 the same locations, at different depths, where for every location the
 species and the amount of species are determined.
 
 The first chart I want to make is to see how much of every species is
 collected in total in a bar or piechart.
 Then I want to make a few charts with the species per location and per 
depth
 
 Here is a subset of my dataset
 
 Station   Latitude(S)   Longitude(E)   Depth(m)   Sa.Code   Sp.Code   N
 UPG02   -5.122355036   119.339401   4   UPG02_4   Amphis_lesson   398
 UPG02   -5.122355036   119.339401   4   UPG02_4   Amphis_radiat   58
 UPG02   -5.122355036   119.339401   4   UPG02_4   Penero_planat   3
 UPG02   -5.122355036   119.339401   4.8   UPG02_4.8   Sphero_sp   5
 UPG02   -5.122355036   119.339401   4.8   UPG02_4.8   Amphis_lesson 204
 UPG02   -5.122355036   119.339401   4.8   UPG02_4.8   Amphis_radiat   18
 UPG02   -5.122355036   119.339401   9   UPG02_9   Sphero_sp   1
 UPG02   -5.122355036   119.339401   9   UPG02_9   Eponid_repand   2
 UPG02   -5.122355036   119.339401   9   UPG02_9   Planor_sp   7
 UPG02   -5.122355036   119.339401   15   UPG02_15   Opercu_ammono   1
 UPG02   -5.122355036   119.339401   15   UPG02_15   Hetero_depres   94
 UPG02   -5.122355036   119.339401   15   UPG02_15   Amphis_lesson   101
 UPG02   -5.122355036   119.339401   18   UPG02_18   Sphero_sp   3
 UPG02   -5.122355036   119.339401   18   UPG02_18   Millio_sp   1
 UPG02   -5.122355036   119.339401   18   UPG02_18   Calcar_mayori   56
 UPG03   -5.136863021   119.387289   3   UPG03_3   Millio_sp   2
 UPG03   -5.136863021   119.387289   3   UPG03_3   Sahuli_sp1   1
 UPG03   -5.136863021   119.387289   3   UPG03_3   Elphid_cratic   20
 UPG03   -5.136863021   119.387289   4   UPG03_4   Planor_sp   1
 UPG03   -5.136863021   119.387289   4   UPG03_4   Opercu_elegan   1
 UPG03   -5.136863021   119.387289   4   UPG03_4   Septot_sp   1
 UPG03   -5.136863021   119.387289   5   UPG03_5   Sphero_sp   1
 UPG03   -5.136863021   119.387289   5   UPG03_5   Millio_sp   1
 UPG03   -5.136863021   119.387289   5   UPG03_5   Ammoni_sp1   1
 UPG03   -5.136863021   119.387289   6   UPG03_6   Calcar_sp1   2
 UPG03   -5.136863021   119.387289   6   UPG03_6   Calcar_mayori   68
 UPG03   -5.136863021   119.387289   6   UPG03_6   Elphid_cratic   17
 UPG03   -5.136863021   119.387289   9   UPG03_9   Sphero_sp   2
 UPG03   -5.136863021   119.387289   9   UPG03_9   Calcar_mayori   323
 UPG03   -5.136863021   119.387289   9   UPG03_9   Calcar_spengl   2
 UPG28   -5.122355036   119.339401   5   UPG28_5   Penero_planat   8
 UPG28   -5.122355036   119.339401   5   UPG28_5   Amphis_latera   1
 UPG28   -5.122355036   119.339401   5   UPG28_5   Sorite_sp   1
 UPG28   -5.122355036   119.339401   8   UPG28_8   Bilocu_sp3   1
 UPG28   -5.122355036   119.339401   8   UPG28_8   Verteb_sp   1
 UPG28   -5.122355036   119.339401   8   UPG28_8   Penero_planat   7
 UPG28   -5.122355036   119.339401   11   UPG28_11   Placop_c.f.   1
 UPG28   -5.122355036   119.339401   11   UPG28_11   Sphero_sp   2
 UPG28   -5.122355036   119.339401   11   UPG28_11   Siphon_siphon   1
 UPG28   -5.122355036   119.339401   14   UPG28_14   Sphero_sp   1
 UPG28   -5.122355036   119.339401   14   UPG28_14   Sorite_sp   1
 UPG28   -5.122355036   119.339401   14   UPG28_14   Spirol_hadaii   1
 UPG28   -5.122355036   119.339401   17   UPG28_17   Sphero_sp   3
 UPG28   -5.122355036   119.339401   17   UPG28_17   Siphon_siphon   1
 UPG28   -5.122355036   119.339401   17   UPG28_17   Sorite_sp   1
 UPG32   -5.136863021   119.387289   4   UPG32_4   Pyrgo_striol   1
 UPG32   -5.136863021   119.387289   4   UPG32_4   Ammoma_alveol   1
 UPG32   -5.136863021   119.387289   4   UPG32_4   Quinqu_netstr   1
 UPG32   -5.136863021   119.387289   6   UPG32_6   Neorot_calcar   1
 UPG32   -5.136863021   119.387289   6   UPG32_6   Quinqu_c.f.ag   1
 UPG32   -5.136863021   119.387289   6   UPG32_6   Amphis_lesson   50
 UPG32   -5.136863021   119.387289   8   UPG32_8   Spirol_sp3   1
 UPG32   -5.136863021   119.387289   8   UPG32_8   Triloc_tricar   1
 UPG32   -5.136863021   119.387289   8   UPG32_8   Amphis_lesson   34

[[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] confidence intervals with glmmPQL

2012-11-15 Thread Sally_roman
Hi - I am using R version 2.13.0.  I have run several GLMMs using the glmmPQL
function to model the proportion of fish caught in one net to the total
caught in both nets by length.  I started with a polynomial regression full
model with three length terms: l, l^2, and l^3 (l=length).  The length terms
and intercept were the fixed effects and the random effect was a paired haul
(n=18).  

m1-glmmPQL(fixed=Proportion~1+Length+second+third,random=~1|Pair,family=binomial,data=species,verbose=T,niter=2,weight=(Experimental+Control))

For the majority of the models, I ended up with a constant model with no
length effect.  The issue I am having is with the confidence intervals that
were calculated.  For two models the CIs are not symmetrical around the mean
proportion from the model.  The CIs for the other constant models are
symmetrical around the mean.  I was wondering if anyone has an idea why this
would be or if anyone has any suggestions.   
Thanks Sally 



--
View this message in context: 
http://r.789695.n4.nabble.com/confidence-intervals-with-glmmPQL-tp4649637.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 KNN Regression Help

2012-11-15 Thread bonjovi
Hi Experts,I'm writing up my thesis on open source data mining at the moment
and I have to do some simple R experiments; however, I have very little
experience with R.. And I am hoping one of you can please help me out:)I
need need to run a regression task that uses the KNN algorithm with k = 5
and cross validation = 10 on the computer hardware datset from the uci repo
and report the RMSE. All other parameters should be set to their default
values (if possible). I am hoping one of you experts can please help me out
with the
code?http://archive.ics.uci.edu/ml/datasets/Computer+Hardwarethanks,Bonjovi



--
View this message in context: 
http://r.789695.n4.nabble.com/R-KNN-Regression-Help-tp4649638.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] Changing start and end in a time serie

2012-11-15 Thread Laura Catalina Echeverri Guzmán
Hello everyone,

I have a time serie created with the function ts(), starting in 2006/01 and
ending in 2011/01. If I want to use the same data of the firsts two years
of that serie in a new one that starts and ends in years later, say 2012/01
and 2013/12, how can I do it?

Thanks in advance!
-- 
Laura Catalina Echeverri Guzmán

[[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] Switch Groups in ehplot (x-axis)

2012-11-15 Thread DusanP
Hello Peter,

I checked for the levels() and reorder(), but I can't make it work. R
classifies the Groups (factor) by alphabetical order, but I would just
like to make him understand that it is ordered (is.ordered()) in my data
frame.

Here is my code : 

abs1-spleen*p1*p2*cd8
length(abs1) # = 13
abs-c(0.499,0.73,0.5,0.75,abs1)
symb-rep(c(17,15,17,15,19),times=c(2,2,5,5,3))
noms-rep(c(WT (NI),Bim-/-Bid-/-
(NI),WT,Bim-/-Bid-/-,Bim-/-Noxa-/-),times=c(2,2,5,5,3))

df-data.frame(abs,symb,noms)

ehplot(df$abs,df$noms,offset=0.1,intervals=10,median=FALSE,pch=df$symb,
xlab=Recipient mice strain (CD45.2),ylab=# CD8alpha DC x 10^6,
main=Absolute number of CD8alpha DCs in spleen,ylim=c(0,3))

Thank you for your help

Dusan



--
View this message in context: 
http://r.789695.n4.nabble.com/Switch-Groups-in-ehplot-x-axis-tp4649485p4649632.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] Importing Data for a two sample t-test

2012-11-15 Thread arun
Hi,

Not sure why you wanted to separate A and B for a two sample t-test.
dat1-read.table(text=
weights  company
1  A
2  A 
2  B
3  B
,sep=,header=TRUE,stringsAsFactors=FALSE)
 t.test(weights~company,data=dat1)

#    Welch Two Sample t-test
#
#data:  weights by company 
#t = -1.4142, df = 2, p-value = 0.2929
#alternative hypothesis: true difference in means is not equal to 0 
#95 percent confidence interval:
 #-4.042435  2.042435 
#sample estimates:
#mean in group A mean in group B 
  #  1.5 2.5 

In case, you wanted to separate A and B:
library(reshape2)
dcast(dat1,weights~company,value.var=weights)
#  weights  A  B
#1   1  1 NA
#2   2  2  2
#3   3 NA  3

Hope it helps.

A.K.



- Original Message -
From: nilsonern nilson...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Wednesday, November 14, 2012 11:52 PM
Subject: [R] Importing Data for a two sample t-test

I am trying to do a two sample t-test with data that i received in a text
document.  one list has the slab weights and the second has the company it
is associated with.  here is an example.

weights  company
1                  A
2                  A  
2                  B
3                  B

I was able to import the data but i cannot figure out how separate the data. 
I want to put them in two separate sets, one being A and one being B.  Any
help would be appreciated.  Thanks.



--
View this message in context: 
http://r.789695.n4.nabble.com/Importing-Data-for-a-two-sample-t-test-tp4649565.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] 'scan' in a script?

2012-11-15 Thread yofiffy
It looks like you are trying to use the scan function to pause some script
being called with the source function until you provide user input.

To do this, you need to specify the argument file=stdin when scan runs
inside a process.  EG scan(file='stdin', nmax=1).  In my Linux terminal, at
least, (using 2.15) I lose the prompt (which formerly defaulted to '1:') and
have to enter some arbitrary value like '1' (whereas hitting enter with no
value entered counted as input when running from an interactive session).




--
View this message in context: 
http://r.789695.n4.nabble.com/scan-in-a-script-tp898837p4649634.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] cluster analysis in R

2012-11-15 Thread KitKat
I have two issues. 

1-I am trying to use morphology to identify gender. I have 9 variables, both
continuous and categorical. I was using two-step cluster analysis in SPSS
because two-step could deal with different types of variables. But the
output tells me that an animal is in cluster 1 or 2, it does not give me a
probability (ex. 0.70 cluster 2).  I also did not want to specify that I
want two clusters, I wanted to see if analysis would naturally give me two
clusters. These were all advantages to using SPSS but now I'm having
trouble.

Does cluster analysis in R give probabilities?
Which type of cluster analysis in R is best to use? I did not think
hierarchical analysis was a great choice, but maybe I'm wrong. I don't want
to create the average variable, I want the analysis to do it on its own. 
I'm also new to R so would have to figure out the right codes to enter, etc.

2-I was also told to analyze each variable on its own before including it in
cluster analysis. I had first included them all then teased out which ones
were not important, but now have been asked to do the reverse. I cannot do
cluster analysis on one variable -for example, one variable is either
present or absent on an individual so of course cluster analysis gives me
two clusters, one representing present and one representing absent. I was
told to use regression, but how can regression also not give the same
result? I feel like it would give me a line connecting a bunch of 0s to 1s.
I don't know what to use, or if I can analyze each variable like this before
putting them into cluster analysis. I ultimately want to only use the
smallest number of variables necessary to identify gender. 

I have tried reading manuals etc and talking to people at my school, but
nothing has helped. If anyone has any insight, that would be much
appreciated
Thank you!



--
View this message in context: 
http://r.789695.n4.nabble.com/cluster-analysis-in-R-tp4649635.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] Selecting the non-attribute part of an object

2012-11-15 Thread Jonathan Dushoff
I have two matrices, generated by R functions that I don't understand.
 I want to confirm that they're the same, but I know that they have
different attributes.

If I want to compare the dimnames, I can say

 identical(attr(tm, dimnames), attr(tmm, dimnames))
[1] FALSE

or even:

 identical(dimnames(tm), dimnames(tmm))
[1] FALSE

But I can't find any good way to compare the main part of objects.

What I'm doing now is:

 tm_new - tm
 tmm_new - tmm

 attributes(tm_new) - attributes(tmm_new) - NULL

 identical(tm_new, tmm_new)
[1] TRUE

But that seems very inaesthetic, besides requiring that I create two
pointless objects.

I have read ?attributes, ?attr and some web introductions to how R
objects work, but have not found an answer.

Thanks for any help.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 create a 95 percent confidence interval using the diference of the mean using Bootstrap

2012-11-15 Thread Tania Patiño
Hello all, could you please tell me how to create a 95 percent confidence
interval using R, if I have the next data:

 blue
 [1]  4 69 87 35 39 79 31 79 65 95 68 62 70 80 84 79 66 75 59 77 36 86 39
85 74
[26] 72 69 85 85 72

 red
 [1] 62 80 82 83  0 81 28 69 48 90 63 77  0 55 83 85 54 72 58 68 88 83 78
30 58
[26] 45 78 64 87 65

Build a confidence interval of 95 % for the difference of the medias using
BOOTSTRAP.

Thank you,

Fjaril

[[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] using ifelse to remove NA's from specific columns of a data frame containing strings and numbers

2012-11-15 Thread arun
HI,

But, this replace second column NAs to 1.  May be, the na.replace() should be 
applied to df1[,-1]

df1-read.table(text=
col1 col2 col3
A   15.5   8.5
A   8.5    7.5
A   NA NA
B   8.0   6.0
B   NA NA
B   9.0   10.0
,sep=,header=TRUE,stringsAsFactors=FALSE)
df2-df1[,-1]
na.replace-seq(1:ncol(df2))-1
df2[,names(df2)]-sapply(1:dim(df2)[2],function(ii){ifelse(is.na(df2[,ii]),na.replace[ii],df2[,ii])})
df2$col1-df1$col1
df2[order(names(df2))]
#  col1 col2 col3
#1    A 15.5  8.5
#2    A  8.5  7.5
#3    A  0.0  1.0
#4    B  8.0  6.0
#5    B  0.0  1.0
#6    B  9.0 10.0
A.K.





- Original Message -
From: soon yi soon...@ymail.com
To: r-help@r-project.org
Cc: 
Sent: Thursday, November 15, 2012 2:29 PM
Subject: Re: [R] using ifelse to remove NA's from specific columns of a data 
frame containing strings and numbers

#Data
df-data.frame(id=letters[1:10],var1=rnorm(10,10,5),var2=rnorm(10,5,2),var3=rnorm(10,1,1))
#Missing
df$var1[2]-df$var2[c(2,6)]-df$var3[c(2,5)]-NA

na.replace-seq(1:ncol(df))-1

df[,names(df)]-sapply(1:dim(df)[2], function(ii)
{ifelse(is.na(df[,ii]),na.replace[ii],df[,ii])} )




David Romano-2 wrote
 Hi everyone,
 
 I have a data frame one of whose columns is a character vector and the
 rest
 are numeric, and in debugging a script, I noticed that an ifelse call
 seems
 to be coercing the character column to a numeric column, and producing
 unintended values as a result.   Roughly, here's what I tried to do:
 
 df: a data frame with, say, the first column as a character column and the
 second and third columns numeric.
 
 also: NA's occur only in the numeric columns, and if they occur in one,
 they occur in the other as well.
 
 I wanted to replace the NA's in column 2 with 0's and the ones in column 3
 with 1's, so first I did this:
 
 na.replacements -ifelse(col(df)==2,0,1).
 
 Then I used a second ifelse call to try to remove the NA's as I wanted,
 first by doing this:
 
 clean.df - ifelse(is.na(df), na.replacements, df),
 
 which produced a list of lists vaguely resembling df, with the NA's mostly
 intact, and so then I tried this:
 
 clean.df - ifelse(is.na(df), na.replacements, unlist(df)),
 
 which seems to work if all the columns are numeric, but otherwise changes
 strings to numbers.
 
 I can't make sense of the help documentation enough to clear this up, but
 my guess is that the yes and no values passed to ifelse need to be
 vectors, in which case it seems I'll have to use another approach
 entirely,
 but even if is not the case and lists are acceptable, I'm not sure how to
 convert a mixed-mode data frame into a vector-like list of elements (which
 I would hope would work).
 
 I'd be grateful for any suggestions!
 
 Thanks,
 David Romano
 
     [[alternative HTML version deleted]]
 
 __

 R-help@

  mailing list
 https://stat.ethz.ch/mailman/listinfo/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 this message in context: 
http://r.789695.n4.nabble.com/using-ifelse-to-remove-NA-s-from-specific-columns-of-a-data-frame-containing-strings-and-numbers-tp4649599p4649642.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] Selecting the non-attribute part of an object

2012-11-15 Thread Bert Gunter
max(abs(x-y))   numerical tolerance of your choice

-- Bert

On Thu, Nov 15, 2012 at 11:52 AM, Jonathan Dushoff dush...@mcmaster.ca wrote:
 I have two matrices, generated by R functions that I don't understand.
  I want to confirm that they're the same, but I know that they have
 different attributes.

 If I want to compare the dimnames, I can say

 identical(attr(tm, dimnames), attr(tmm, dimnames))
 [1] FALSE

 or even:

 identical(dimnames(tm), dimnames(tmm))
 [1] FALSE

 But I can't find any good way to compare the main part of objects.

 What I'm doing now is:

 tm_new - tm
 tmm_new - tmm

 attributes(tm_new) - attributes(tmm_new) - NULL

 identical(tm_new, tmm_new)
 [1] TRUE

 But that seems very inaesthetic, besides requiring that I create two
 pointless objects.

 I have read ?attributes, ?attr and some web introductions to how R
 objects work, but have not found an answer.

 Thanks for any help.

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



-- 

Bert Gunter
Genentech Nonclinical Biostatistics

Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm

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


[R] strip.custom() with more than one conditioning variable

2012-11-15 Thread p_connolly
Suppose I wanted to plot the barley data like this:

dotplot(variety ~ yield | year+ site, barley,
strip = strip.custom(style = 4))

The factor levels are far too long for that to be useful.  I can
overcome that problem if I shorten the levels like this:

dotplot(variety ~ yield | year + site, barley,
strip = strip.custom(style = 4,
  factor.levels =  substring(levels(barley$site), 1, 1)))

But that messes up the year levels.  So I try to have it influence
only the site levels:

dotplot(variety ~ yield | year+ site, barley,
strip = strip.custom(which.given = 2, style = 4,
  factor.levels =  substring(levels(barley$site), 1, 1)))

But then the year strip is omitted altogether.  How do I specify
a different list for different which.given numbers?

In this case, I know I could simply redefine the levels in the factor
but that's not an option where I wish to apply this method.

TIA
Patrick

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] assigning NULL to a list element without changing the length of the list

2012-11-15 Thread Gonçalo Ferraz
Hi,

I have a list:

tmp0 - list(a=1, b=2, c=3)

And I realize that I can append a NULL element to the end of this list, just by 
writing:

length(tmp0) - 4

Now, the question is, how can I assign NULL to one of the existing list 
elements without changing the length of the list?

Please note I am working from inside a for loop that is working on one list 
element at a time and in some circumstances I want to 
set one element to NULL. So, specifying the whole list again as in:

tmp0 - list(a=1,b=NULL,c=3)

is not an option.

But writing, say:

tmp0 [[2]] - NULL

is not an option either, because it leaves me with a list of length 2.

Is there a solution for this?

Thank you

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] assigning NULL to a list element without changing the length of the list

2012-11-15 Thread William Dunlap
tmp0 - list(a=1, b=2, c=3)
tmp0[b] - list(NULL) # single [, list(NULL), not double [[ and bare NULL
str(tmp0)
# List of 3
#  $ a: num 1
#  $ b: NULL
#  $ c: num 3

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Gonçalo Ferraz
 Sent: Thursday, November 15, 2012 1:01 PM
 To: r-help@r-project.org
 Subject: [R] assigning NULL to a list element without changing the length of 
 the list
 
 Hi,
 
 I have a list:
 
 tmp0 - list(a=1, b=2, c=3)
 
 And I realize that I can append a NULL element to the end of this list, just 
 by writing:
 
 length(tmp0) - 4
 
 Now, the question is, how can I assign NULL to one of the existing list 
 elements without
 changing the length of the list?
 
 Please note I am working from inside a for loop that is working on one list 
 element at a
 time and in some circumstances I want to
 set one element to NULL. So, specifying the whole list again as in:
 
 tmp0 - list(a=1,b=NULL,c=3)
 
 is not an option.
 
 But writing, say:
 
 tmp0 [[2]] - NULL
 
 is not an option either, because it leaves me with a list of length 2.
 
 Is there a solution for this?
 
 Thank you
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] cluster analysis in R

2012-11-15 Thread Ingmar Visser
Dear KitKat,

After installing R and reading some introductory material on getting
started with R you may want to check the CRAN task view on cluster analysis:
http://cran.r-project.org/web/views/Cluster.html
which has many useful references to all kinds and flavors of clustering
techniques, hierarchical or not, selecting the nr of clusters based on some
model selection statistic, et cetera.

hth, Ingmar

On Thu, Nov 15, 2012 at 7:14 PM, KitKat katherinewri...@trentu.ca wrote:

 I have two issues.

 1-I am trying to use morphology to identify gender. I have 9 variables,
 both
 continuous and categorical. I was using two-step cluster analysis in SPSS
 because two-step could deal with different types of variables. But the
 output tells me that an animal is in cluster 1 or 2, it does not give me a
 probability (ex. 0.70 cluster 2).  I also did not want to specify that I
 want two clusters, I wanted to see if analysis would naturally give me two
 clusters. These were all advantages to using SPSS but now I'm having
 trouble.

 Does cluster analysis in R give probabilities?
 Which type of cluster analysis in R is best to use? I did not think
 hierarchical analysis was a great choice, but maybe I'm wrong. I don't want
 to create the average variable, I want the analysis to do it on its own.
 I'm also new to R so would have to figure out the right codes to enter,
 etc.

 2-I was also told to analyze each variable on its own before including it
 in
 cluster analysis. I had first included them all then teased out which ones
 were not important, but now have been asked to do the reverse. I cannot do
 cluster analysis on one variable -for example, one variable is either
 present or absent on an individual so of course cluster analysis gives me
 two clusters, one representing present and one representing absent. I was
 told to use regression, but how can regression also not give the same
 result? I feel like it would give me a line connecting a bunch of 0s to 1s.
 I don't know what to use, or if I can analyze each variable like this
 before
 putting them into cluster analysis. I ultimately want to only use the
 smallest number of variables necessary to identify gender.

 I have tried reading manuals etc and talking to people at my school, but
 nothing has helped. If anyone has any insight, that would be much
 appreciated
 Thank you!



 --
 View this message in context:
 http://r.789695.n4.nabble.com/cluster-analysis-in-R-tp4649635.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] depmixS4 prediction

2012-11-15 Thread Ingmar Visser
Dear EJ,

The depmixS4 package has no forecasting or predict functions, but as you
note, the forecast distribution is a relatively straightforward function of
the parameters. The posterior function provides you with the probability
distribution over the states at the end of your sequence and the transition
matrix can be used to compute the state distributions ahead.

Let me know if you have more questions, best, Ingmar

PS: you may have gotten a quicker answer had the message also been sent to
me directly.

On Thu, Nov 15, 2012 at 5:48 AM, Epic John epicj...@gmail.com wrote:

 I am getting started with using the depmixS4 package. First, I would like
 to see I am very impressed with its speed and flexibility.

 The question I have is regarding predicting on new data. I want to fit the
 model on some sequences with observed responses, and then make predictions
 on the right end of the sequences where the responses are not observed. I
 see no prediction functionality anywhere, and am not sure what the best way
 to formulate something like is with the package without reinventing the
 wheel.

 I once i have a fitted model, i would like to apply it to sequences where
 the response variables on the right end of the sequence are unobserved, and
 get the prediction for those (conditioned on observed covariates for the
 response) using the filtering or smoothing distributions.

 I could ultimately pull out the relevant parameters of the conditional
 distribution of the response in each hidden state, the transition
 probabilities,  rightmost posterior probability on the fully observed
 sequence , and write my own code to make predictions, but am wondering if
 there is a more direct way of doing it in the package.

 Thanks in advance for any suggestions,

 EJ

 [[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] survreg gompertz

2012-11-15 Thread David Winsemius

On Nov 15, 2012, at 5:38 AM, Matthias Ziehm wrote:

 Hi all,
 
 Sorry if this has been answered already, but I couldn't find it in the 
 archives or general internet.

A Markmail/Rhelp search on:  gompertz survreg  ...brings this link to a reply 
by Terry Therneau. Seems to address everything you asked and a bit more

http://markmail.org/search/?q=list%3Aorg.r-project.r-help+gompertz+survreg#query:list%3Aorg.r-project.r-help%20gompertz%20survreg+page:1+mid:6xdlsmo272oa7zkw+state:results

(Depending on how your mailer breaks URLs you may need to paste it back 
together.)
 
 Is it possible to implement the gompertz distribution as survreg.distribution 
 to use with survreg of the survival library?
 I haven't found anything and recent attempts from my side weren't succefull 
 so far.
 
 I know that other packages like 'eha' and 'flexsurv' offer functions similar 
 to survreg with gompertz support. However, due to the run-time environment 
 were this needs to be running in the end, I can't use these packages :(
 
 Same questions for the gompertz-makeham distribution.
 
 Many thanks!
 
 Matthias
-- 

David Winsemius, MD
Alameda, CA, USA

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Selecting the non-attribute part of an object

2012-11-15 Thread William Dunlap
all.equal() will give some details on the differences between your objects.
If you don't care that some attribute will differ, either ignore all.equal's
output concerning it or remove it before giving the object to all.equal.
E.g., if you don't care about dimnames but do care about dimensions do
   canonicalize - function(x) structure(x, dimnames=NULL)
   all.equal(canonicalize(tm), canonicalize(tmm)) 

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
 Behalf
 Of Jonathan Dushoff
 Sent: Thursday, November 15, 2012 11:53 AM
 To: r-help@r-project.org
 Subject: [R] Selecting the non-attribute part of an object
 
 I have two matrices, generated by R functions that I don't understand.
  I want to confirm that they're the same, but I know that they have
 different attributes.
 
 If I want to compare the dimnames, I can say
 
  identical(attr(tm, dimnames), attr(tmm, dimnames))
 [1] FALSE
 
 or even:
 
  identical(dimnames(tm), dimnames(tmm))
 [1] FALSE
 
 But I can't find any good way to compare the main part of objects.
 
 What I'm doing now is:
 
  tm_new - tm
  tmm_new - tmm
 
  attributes(tm_new) - attributes(tmm_new) - NULL
 
  identical(tm_new, tmm_new)
 [1] TRUE
 
 But that seems very inaesthetic, besides requiring that I create two
 pointless objects.
 
 I have read ?attributes, ?attr and some web introductions to how R
 objects work, but have not found an answer.
 
 Thanks for any help.
 
 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] how to view source code of a function inside a package?

2012-11-15 Thread Suzen, Mehmet
It might be a C code wrapped around.
-m

On Thu, Nov 15, 2012 at 8:21 PM, C W tmrs...@gmail.com wrote:
 Dear list,
 I am trying to look at the function inside a package.  I know that
 methods() would do the trick, but what if the function is hidden?  I have a
 problem displaying the hidden function.

 Say, for example the MCMC package.  How do you view the code of that
 function?

 something like this:

 which

 function (x, arr.ind = FALSE, useNames = TRUE)

 {

 wh - .Internal(which(x))

 if (arr.ind  !is.null(d - dim(x)))

 arrayInd(wh, d, dimnames(x), useNames = useNames)

 else wh

 }

 bytecode: 0x1021eef50

 environment: namespace:base

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



-- 
Mehmet Süzen, Ph.D. ( Dr.phil.nat. )
su...@acm.org

| PRIVILEGED AND CONFIDENTIAL COMMUNICATION This e-mail transmission,
and any documents, files or previous e-mail messages attached to it,
may contain confidential information that is legally privileged. If
you are not the intended recipient or a person responsible for
delivering it to the intended recipient, you are hereby notified that
any disclosure, copying, distribution or use of any of the information
contained in or attached to this transmission is STRICTLY PROHIBITED
within the applicable law. If you have received this transmission in
error, please: (1) immediately notify me by reply e-mail to
su...@acm.org,  and (2) destroy the original transmission and its
attachments without reading or saving in any manner. |

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Installing R on Ubuntu

2012-11-15 Thread Suzen, Mehmet
Try  Prof. Wilkinson's recent blog entry:

http://darrenjw.wordpress.com/2012/11/10/keeping-r-up-to-date-on-ubuntu-linux/

On Thu, Nov 15, 2012 at 5:14 PM, Karel van Duijvenboden
viera...@gmail.com wrote:
 Hello R-help team,

 I seek your help (for what is most likely a very simple problem). I'm new
 to Ubuntu and tried to install R using the Ubuntu Software Center. However,
 after clicking the install command, I always get prompted with the error 
 Failed to download package files --- check your internet connection.
 Details: Failed to fetch
 http://archive.ubuntu.com/ubuntu/pool/main/a/apparmor/dh-apparmor_2.7.102-0ubuntu3.1_all.deb404
  Not Found [IP: 91.189.92.200 80]

 However, my internet connection is perfectly fine and I've already
 installed a bunch of programs using the Software Center without any
 problems. I've tried various of the available R packages (also the
 Rcommander) and always get this same error. Perhaps it has something to do
 with the server/mirror?

 Alternatively, I've downloaded a .zip of the package, but so far I've
 failed to install the program. With me, for now, being an unequivocal
 Ubuntu dummy I would prefer the straightforward Software Center route and
 in any case I wonder why it does not work for me.

 Best regards and thanks in advance!

 Karel van Duijvenboden (Netherlands)

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



-- 
Mehmet Süzen, Ph.D. ( Dr.phil.nat. )
su...@acm.org

| PRIVILEGED AND CONFIDENTIAL COMMUNICATION This e-mail transmission,
and any documents, files or previous e-mail messages attached to it,
may contain confidential information that is legally privileged. If
you are not the intended recipient or a person responsible for
delivering it to the intended recipient, you are hereby notified that
any disclosure, copying, distribution or use of any of the information
contained in or attached to this transmission is STRICTLY PROHIBITED
within the applicable law. If you have received this transmission in
error, please: (1) immediately notify me by reply e-mail to
su...@acm.org,  and (2) destroy the original transmission and its
attachments without reading or saving in any manner. |

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 create a 95 percent confidence interval using the diference of the mean using Bootstrap

2012-11-15 Thread Rui Barradas

Hello,

Try the following.

?boot::boot
x - scan(text=
 4 69 87 35 39 79 31 79 65 95 68 62 70 80 84 79 66 75 59 77 36 86 39
85 74 72 69 85 85 72)

y - scan(text=
62 80 82 83  0 81 28 69 48 90 63 77  0 55 83 85 54 72 58 68 88 83 78
30 58 45 78 64 87 65)

diffmeans - function(x, i) mean(x[i, 1] - x[i, 2])

res - boot::boot(cbind(x, y), diffmeans, R = 1000)
quantile(res$t, probs = c(0.025, 0.975))  # CI
res$t0  # estimate

Hope this helps,

Rui Barradas

Em 15-11-2012 19:52, Tania Patiño escreveu:

Hello all, could you please tell me how to create a 95 percent confidence
interval using R, if I have the next data:


blue

  [1]  4 69 87 35 39 79 31 79 65 95 68 62 70 80 84 79 66 75 59 77 36 86 39
85 74
[26] 72 69 85 85 72


red

  [1] 62 80 82 83  0 81 28 69 48 90 63 77  0 55 83 85 54 72 58 68 88 83 78
30 58
[26] 45 78 64 87 65

Build a confidence interval of 95 % for the difference of the medias using
BOOTSTRAP.

Thank you,

Fjaril

[[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] Can you have a by variable in Lag function as in SAS

2012-11-15 Thread Nordlund, Dan (DSHS/RDA)
 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-bounces@r-
 project.org] On Behalf Of ramoss
 Sent: Thursday, November 15, 2012 11:56 AM
 To: r-help@r-project.org
 Subject: [R] Can you have a by variable in Lag function as in SAS
 
 Hello,
 
 I want to use lag on a time variable but I have to take date into
 consideration ie I don't want days to overlap ie:
 I don't want my first time of today to match my last time of yeterday.
 
 In SAS I would use :
 
 data x;
   set y;
   by date tim;
   previous=lag(tim);
   if first.date then
  do;
   previous=.;
  end;
 run;
 
 How can I do something similar in R?  I can't find any examples
 anywhere.
 
 Thank you all for your help.
 
 

I  haven't seen a response to this question yet, so here is an approach that 
may work for you.  Let's say you have a data frame called dat that contains 
your variables date and tim.  Then using the Lag() function from the Hmisc 
package you could do something like this

library(Hmisc)
dat$previous - ave(dat$tim,dat$date,FUN=Lag)


Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] strip.custom() with more than one conditioning variable

2012-11-15 Thread Duncan Mackay

Hi Patrick

Not sure what you finally want to achieve but will this do?

I have reduced the size of the text to make them readible

 dotplot(variety ~ yield | year+ site, barley,
strip = strip.custom(which.given = 2, style = 4,
  factor.levels = paste(levels(barley$year), 
substring(levels(barley$site), 1, 1)),

  par.strip.text = list(cex = 0.75))
)

Regards

Duncan


Duncan Mackay
Department of Agronomy and Soil Science
University of New England
Armidale NSW 2351
Email: home: mac...@northnet.com.au



At 06:53 16/11/2012, you wrote:

Suppose I wanted to plot the barley data like this:

dotplot(variety ~ yield | year+ site, barley,
strip = strip.custom(style = 4))

The factor levels are far too long for that to be useful.  I can
overcome that problem if I shorten the levels like this:

dotplot(variety ~ yield | year + site, barley,
strip = strip.custom(style = 4,
  factor.levels =  substring(levels(barley$site), 1, 1)))

But that messes up the year levels.  So I try to have it influence
only the site levels:

dotplot(variety ~ yield | year+ site, barley,
strip = strip.custom(which.given = 2, style = 4,
  factor.levels =  substring(levels(barley$site), 1, 1)))

But then the year strip is omitted altogether.  How do I specify
a different list for different which.given numbers?

In this case, I know I could simply redefine the levels in the factor
but that's not an option where I wish to apply this method.

TIA
Patrick

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] create function to solve derivative

2012-11-15 Thread Rolf Turner

On 16/11/12 02:40, e-letter wrote:

Readers,

A data set comprises

A   B   C
10  6   .2
20  7   .4
30  8   .16
40  9   .0256

My requirement is to obtain the derivative for values of A with
respect to B, create a function in R and plot this derivative against
another variable (e.g. values in column C).

Have searched the mailing list and found reference to a function 'D',
but the help accessed via '?D' and '?deriv' does not explain how to
write a derivative function.

Could someone please direct me to the relevant parts of the manual to begin?


Your question makes little sense.  Functions have derivatives --- at
least some of them do.  Data sets do not have derivatives.  The
functions D(), deriv() etc. work on specified analytic expressions
for functions --- data sets do not come into the picture.

What you might possibly want to do is to fit a spline to your data
and take the derivative of the spline.  The function splinefun()
could be what you need.

cheers,

Rolf Turner

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] cluster analysis in R

2012-11-15 Thread Jose Iparraguirre
Have a look at the package mclust.
Jose

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
Ingmar Visser [i.vis...@uva.nl]
Sent: 15 November 2012 21:10
To: KitKat
Cc: r-help@r-project.org
Subject: Re: [R] cluster analysis in R

Dear KitKat,

After installing R and reading some introductory material on getting
started with R you may want to check the CRAN task view on cluster analysis:
http://cran.r-project.org/web/views/Cluster.html
which has many useful references to all kinds and flavors of clustering
techniques, hierarchical or not, selecting the nr of clusters based on some
model selection statistic, et cetera.

hth, Ingmar

On Thu, Nov 15, 2012 at 7:14 PM, KitKat katherinewri...@trentu.ca wrote:

 I have two issues.

 1-I am trying to use morphology to identify gender. I have 9 variables,
 both
 continuous and categorical. I was using two-step cluster analysis in SPSS
 because two-step could deal with different types of variables. But the
 output tells me that an animal is in cluster 1 or 2, it does not give me a
 probability (ex. 0.70 cluster 2).  I also did not want to specify that I
 want two clusters, I wanted to see if analysis would naturally give me two
 clusters. These were all advantages to using SPSS but now I'm having
 trouble.

 Does cluster analysis in R give probabilities?
 Which type of cluster analysis in R is best to use? I did not think
 hierarchical analysis was a great choice, but maybe I'm wrong. I don't want
 to create the average variable, I want the analysis to do it on its own.
 I'm also new to R so would have to figure out the right codes to enter,
 etc.

 2-I was also told to analyze each variable on its own before including it
 in
 cluster analysis. I had first included them all then teased out which ones
 were not important, but now have been asked to do the reverse. I cannot do
 cluster analysis on one variable -for example, one variable is either
 present or absent on an individual so of course cluster analysis gives me
 two clusters, one representing present and one representing absent. I was
 told to use regression, but how can regression also not give the same
 result? I feel like it would give me a line connecting a bunch of 0s to 1s.
 I don't know what to use, or if I can analyze each variable like this
 before
 putting them into cluster analysis. I ultimately want to only use the
 smallest number of variables necessary to identify gender.

 I have tried reading manuals etc and talking to people at my school, but
 nothing has helped. If anyone has any insight, that would be much
 appreciated
 Thank you!



 --
 View this message in context:
 http://r.789695.n4.nabble.com/cluster-analysis-in-R-tp4649635.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.

Wrap Up  Run 10k next March to raise vital funds for Age UK

Six exciting new 10k races are taking place throughout the country and we want 
you to join in the fun! Whether you're a runner or not, these are
events are for everyone ~ from walking groups to serious athletes. The Age UK 
Events Team will provide you with a training plan to suit your 
level and lots of tips to make this your first successful challenge of 2012. 
Beat the January blues and raise some vital funds to help us 
prevent avoidable deaths amongst older people this winter.


Sign up now! www.ageuk.org.uk/10k

Coming to; London Crystal Palace, Southport, Tatton Park, Cheshire Harewood 
House, Leeds,Coventry, Exeter


Age UK Improving later life
www.ageuk.org.uk


 

---
Age UK is a registered charity and company limited by guarantee, (registered 
charity number 1128267, registered company number 6825798). 
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

For the purposes of promoting Age UK Insurance, Age UK is an Appointed 
Representative of Age UK Enterprises Limited, Age UK is an Introducer 
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth 
Access for the purposes of introducing potential annuity and health 
cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit 
Solutions Limited and Simplyhealth Access are all authorised and 
regulated by the Financial Services Authority. 
--

This email and any files transmitted with it are confidential and intended 

[R] Step-wise method for large dimension

2012-11-15 Thread farnoosh sheikhi


Hi ,

I want to apply the following code fo my data with 400 predictors.
I was wondering if there ia an alternative way instead of typing 400 predictors 
for the following code.
I really appreciate your help.

fit0-lm(Y~1, data= mydata)
fit.final- lm(Y~X1+X2+X3+.+X400, data=mydata) ???
step(fit0, scope=list(lower=fit0, upper=fit.final), data=mydata, 
direction=forward)
step(fit.final, scope=list(lower=fit.final, upper=fit0), data=mydata, 
direction=backward)
 
Best,Farnoosh Sheikhi
[[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] problem with XML package

2012-11-15 Thread Torus Insurance
Hi List,
I have used XML in R version 2.9.2. The code is working fine using Rv2.9.2
and its related XML package. Now I am using Rv2.13.1 and its related XML
package, but I get the following error:


Error in UseMethod(xmlName, node) :
  no applicable method for 'xmlName' applied to an object of class NULL

Any idea?

Thanks

Arvin

[[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] Error when launching rJava

2012-11-15 Thread Roman Wigger
Hi all

I'd like to launch rJava but get that error:

library(rJava) Error : .onLoad failed in loadNamespace() for 'rJava',
details:
call: dyn.load(file, DLLpath = DLLpath, ...) error: unable to load shared
object
'/home/cloudera/R/x86_64-redhat-linux-gnu-library/2.15/rJava/libs/rJava.so':
libjvm.so: cannot open shared object file: No such file or directory Error:
package/namespace load failed for ‘rJava’

Here are some more information if needed:
[cloudera@localhost ~]$ java -version java version 1.6.0_31
Java(TM) SE Runtime Environment (build 1.6.0_31-b04)
Java HotSpot(TM) 64-Bit Server VM (build 20.6-b01, mixed mode)

I need rJava running to be able to install rhdfs for my cloudera demo vm
cdh3u4.Is ther something wrong with LD_LIBRARY_PATH settings? If yes, how
can I fix that?

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] Removing default loess line from scatterplot ({car})

2012-11-15 Thread nprause
scatterplot() is autogenerating a regression and loess line. I want to remove
the loess line, but can only find samples for how to add it. I definitely do
not have code that adds it (see below), so I am puzzling...

scatterplot(Aroused ~ anxious | group, 
data=data,
xlab=Aroused, 
ylab=Anxious,
main=Arousal and anxiety ratings,
xlim=c(0.5, 9.5), ylim=c(0.5, 9.5),
legend.plot=F,
)
legend(6,2,c(Controls, Patients),group)



--
View this message in context: 
http://r.789695.n4.nabble.com/Removing-default-loess-line-from-scatterplot-car-tp4649668.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] Stepwise

2012-11-15 Thread arun
Hi,
May be this helps:
set.seed(232)
mat1-matrix(sample(1:100,80,replace=TRUE),ncol=8) #with 8 columns
dat1-data.frame(mat1)
 names(dat1)[1]-Y
 form1-as.formula(paste(Y~,paste(names(dat1)[2:8],collapse=+))) #should 
change 8 to 400

fit.final-lm(form1,data=dat1)

fit.final
#Call:
#lm(formula = form1, data = dat1)
#
#Coefficients:
#(Intercept)   X2   X3   X4   X5   X6  
# 143.763081    -0.009030    -1.844810 1.436647    -0.005407    -0.050101  
# X7   X8  
#   0.563285    -1.901918  
A.K.







From: farnoosh sheikhi farnoosh...@yahoo.com
To: arun smartpink...@yahoo.com 
Sent: Thursday, November 15, 2012 6:14 PM
Subject: Stepwise


Hi there,

I want to apply the following code fo my data with 400 predictors.
I was wondering if there is an alternative way instead of typing 400 predictors 
for the following code.
I really appreciate your help.

fit0-lm(Y~1, data= mydata)
fit.final- lm(Y~X1+X2+X3+.+X400, data=mydata) ???
step(fit0, scope=list(lower=fit0, upper=fit.final), data=mydata, 
direction=forward)
step(fit.final, scope=list(lower=fit.final, upper=fit0), data=mydata, 
direction=backward)

Best,Farnoosh Sheikhi 

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Selecting the non-attribute part of an object

2012-11-15 Thread Rolf Turner


I think that what you are looking for is:

all.equal(tm,tmm,check.attributes=FALSE)

But BEWARE:

m   - matrix(1:36,4,9)
mm - matrix(1:36,12,3)
all.equal(m,mm,check.attributes=FALSE)

gives TRUE!!!  I.e. sometimes attributes really are vital characteristics.

cheers,

Rolf Turner

On 16/11/12 08:52, Jonathan Dushoff wrote:

I have two matrices, generated by R functions that I don't understand.
  I want to confirm that they're the same, but I know that they have
different attributes.

If I want to compare the dimnames, I can say


identical(attr(tm, dimnames), attr(tmm, dimnames))

[1] FALSE

or even:


identical(dimnames(tm), dimnames(tmm))

[1] FALSE

But I can't find any good way to compare the main part of objects.

What I'm doing now is:


tm_new - tm
tmm_new - tmm
attributes(tm_new) - attributes(tmm_new) - NULL
identical(tm_new, tmm_new)

[1] TRUE

But that seems very inaesthetic, besides requiring that I create two
pointless objects.

I have read ?attributes, ?attr and some web introductions to how R
objects work, but have not found an answer.

Thanks for any help.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Step-wise method for large dimension

2012-11-15 Thread R. Michael Weylandt
Probably you just want

Y ~ .

where . means everything which doesn't appear elsewhere in the formula.

Michael

On Thu, Nov 15, 2012 at 8:45 PM, farnoosh sheikhi farnoosh...@yahoo.com wrote:


 Hi ,

 I want to apply the following code fo my data with 400 predictors.
 I was wondering if there ia an alternative way instead of typing 400 
 predictors for the following code.
 I really appreciate your help.

 fit0-lm(Y~1, data= mydata)
 fit.final- lm(Y~X1+X2+X3+.+X400, data=mydata) ???
 step(fit0, scope=list(lower=fit0, upper=fit.final), data=mydata, 
 direction=forward)
 step(fit.final, scope=list(lower=fit.final, upper=fit0), data=mydata, 
 direction=backward)

 Best,Farnoosh Sheikhi
 [[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] assigning NULL to a list element without changing the length of the list

2012-11-15 Thread arun
HI,
You could try these:
tmp1-list(a=1,b=NA,c=3,d=NA)
 lapply(tmp1,function(x) if(is.na(x)) NULL else x)  #changing NA to NULL

#$a
#[1] 1
#
#$b
#NULL
#
#$c
#[1] 3
#
#$d
#NULL

#other case;
tmp2-list(a=1,b=3,c=4,d=5)  #want to change list elements a, c to NULL

tmp3-lapply(tmp2,function(x) {if(names(tmp2)[match.call()[[2]][[3]]]%in% 
c(a,c)) NULL else x})

 tmp3
#$a
#NULL
#
#$b
#[1] 3
#
#$c
#NULL
#
#$d
#[1] 5


A.K.




- Original Message -
From: Gonçalo Ferraz gferra...@gmail.com
To: r-help@r-project.org
Cc: 
Sent: Thursday, November 15, 2012 4:01 PM
Subject: [R] assigning NULL to a list element without changing the length of 
the list

Hi,

I have a list:

tmp0 - list(a=1, b=2, c=3)

And I realize that I can append a NULL element to the end of this list, just by 
writing:

length(tmp0) - 4

Now, the question is, how can I assign NULL to one of the existing list 
elements without changing the length of the list?

Please note I am working from inside a for loop that is working on one list 
element at a time and in some circumstances I want to 
set one element to NULL. So, specifying the whole list again as in:

tmp0 - list(a=1,b=NULL,c=3)

is not an option.

But writing, say:

tmp0 [[2]] - NULL

is not an option either, because it leaves me with a list of length 2.

Is there a solution for this?

Thank you

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Removing default loess line from scatterplot ({car})

2012-11-15 Thread Jose Iparraguirre
Always look at the help page. If you type, in this case, ?scatterplot, you'll 
see that all you need to add is the argument smooth=FALSE to omit the loess 
line.

Jose

From: r-help-boun...@r-project.org [r-help-boun...@r-project.org] On Behalf Of 
nprause [nicole.pra...@gmail.com]
Sent: 15 November 2012 23:01
To: r-help@r-project.org
Subject: [R] Removing default loess line from scatterplot ({car})

scatterplot() is autogenerating a regression and loess line. I want to remove
the loess line, but can only find samples for how to add it. I definitely do
not have code that adds it (see below), so I am puzzling...

scatterplot(Aroused ~ anxious | group,
data=data,
xlab=Aroused,
ylab=Anxious,
main=Arousal and anxiety ratings,
xlim=c(0.5, 9.5), ylim=c(0.5, 9.5),
legend.plot=F,
)
legend(6,2,c(Controls, Patients),group)



--
View this message in context: 
http://r.789695.n4.nabble.com/Removing-default-loess-line-from-scatterplot-car-tp4649668.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.

Wrap Up  Run 10k next March to raise vital funds for Age UK

Six exciting new 10k races are taking place throughout the country and we want 
you to join in the fun! Whether you're a runner or not, these are
events are for everyone ~ from walking groups to serious athletes. The Age UK 
Events Team will provide you with a training plan to suit your 
level and lots of tips to make this your first successful challenge of 2012. 
Beat the January blues and raise some vital funds to help us 
prevent avoidable deaths amongst older people this winter.


Sign up now! www.ageuk.org.uk/10k

Coming to; London Crystal Palace, Southport, Tatton Park, Cheshire Harewood 
House, Leeds,Coventry, Exeter


Age UK Improving later life
www.ageuk.org.uk


 

---
Age UK is a registered charity and company limited by guarantee, (registered 
charity number 1128267, registered company number 6825798). 
Registered office: Tavis House, 1-6 Tavistock Square, London WC1H 9NA.

For the purposes of promoting Age UK Insurance, Age UK is an Appointed 
Representative of Age UK Enterprises Limited, Age UK is an Introducer 
Appointed Representative of JLT Benefit Solutions Limited and Simplyhealth 
Access for the purposes of introducing potential annuity and health 
cash plans customers respectively.  Age UK Enterprises Limited, JLT Benefit 
Solutions Limited and Simplyhealth Access are all authorised and 
regulated by the Financial Services Authority. 
--

This email and any files transmitted with it are confidential and intended 
solely for the use of the individual or entity to whom they are 
addressed. If you receive a message in error, please advise the sender and 
delete immediately.

Except where this email is sent in the usual course of our business, any 
opinions expressed in this email are those of the author and do not 
necessarily reflect the opinions of Age UK or its subsidiaries and associated 
companies. Age UK monitors all e-mail transmissions passing 
through its network and may block or modify mails which are deemed to be 
unsuitable.

Age Concern England (charity number 261794) and Help the Aged (charity number 
272786) and their trading and other associated companies merged 
on 1st April 2009.  Together they have formed the Age UK Group, dedicated to 
improving the lives of people in later life.  The three national 
Age Concerns in Scotland, Northern Ireland and Wales have also merged with Help 
the Aged in these nations to form three registered charities: 
Age Scotland, Age NI, Age Cymru.










__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Selecting the non-attribute part of an object

2012-11-15 Thread Jonathan Dushoff
Thanks for all of these useful answers.

Thanks also to Ben Bolker, who told me offline that c() is a general
way to access the main part of an object (not tested).

I also tried:

 identical(matrix(tm), matrix(tmm))
[1] TRUE

which also works, but does _not_ solve the problem Rolf warns about
below (to my disappointment).

JD

On Thu, Nov 15, 2012 at 6:47 PM, Rolf Turner rolf.tur...@xtra.co.nz wrote:

 I think that what you are looking for is:

 all.equal(tm,tmm,check.attributes=FALSE)

 But BEWARE:

 m   - matrix(1:36,4,9)
 mm - matrix(1:36,12,3)
 all.equal(m,mm,check.attributes=FALSE)

 gives TRUE!!!  I.e. sometimes attributes really are vital characteristics.

 cheers,

 Rolf Turner


 On 16/11/12 08:52, Jonathan Dushoff wrote:

 I have two matrices, generated by R functions that I don't understand.
   I want to confirm that they're the same, but I know that they have
 different attributes.

 If I want to compare the dimnames, I can say

 identical(attr(tm, dimnames), attr(tmm, dimnames))

 [1] FALSE

 or even:

 identical(dimnames(tm), dimnames(tmm))

 [1] FALSE

 But I can't find any good way to compare the main part of objects.

 What I'm doing now is:

 tm_new - tm
 tmm_new - tmm
 attributes(tm_new) - attributes(tmm_new) - NULL
 identical(tm_new, tmm_new)

 [1] TRUE

 But that seems very inaesthetic, besides requiring that I create two
 pointless objects.

 I have read ?attributes, ?attr and some web introductions to how R
 objects work, but have not found an answer.

 Thanks for any help.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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.


  1   2   >