Re: [R] advice/opinion on - vs = in teaching R

2010-01-15 Thread Barry Rowlingson
On Fri, Jan 15, 2010 at 3:45 AM, Erin Hodgess erinm.hodg...@gmail.comwrote:

 Hi R People:

 I'm teaching a statistical computing class using R starting next week
 (yay!) and I have an opinion type question, please.

 I'm old school and use - in an assignment.


 You call that 'old school'?? I still use ' x_1'! Of course ESS turns the
underscore into '-' magically.

 Perhaps these guys should redo their tests with slightly different syntax:

http://www.cs.mdx.ac.uk/research/PhDArea/saeed/paper1.pdf

Barry

-- 
blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman

[[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] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Uli Kleinwechter
Dear all,

I'm looking for a way to replace NA's with 0 for a number of variables
which share the same ending and which constitute a subset of a data frame.

Say, for example, there is

 data - data.frame(ax=c(1,2,3,NA,0) , bx=c(3,5,NA,5,1) ,
ay=c(5,NA,2,NA,0) , by=c(4,2,NA,2,1))
 data
  ax bx ay by
1  1  3  5  4
2  2  5 NA  2
3  3 NA  2 NA
4 NA  5 NA  2
5  0  1  0  1

I wish to apply something like  //
//
/ data[is.na(data)] - 0/
//
but not to the entire data frame, rather only to the variables ending
with x.

There should be something which emulates the use of a wildcard, ie.
which makes the operation being carried out for all variables *x. I
tried with grep and glob2rx but did not succeed.

Many thanks for any hints!

Uli Kleinwechter


-- 
Uli Kleinwechter
Agricultural and Food Policy Group (420a)
Faculty of Agricultural Sciences
University of Hohenheim
D-70593 Stuttgart
Phone: (+49) 711 459-22656
Fax: (+49) 711 459-23752
E-mail: u.kleinwech...@uni-hohenheim.de
http://www.uni-hohenheim.de/apo

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] advice/opinion on - vs = in teaching R

2010-01-15 Thread Barry Rowlingson
On Fri, Jan 15, 2010 at 6:57 AM, Ted Harding
ted.hard...@manchester.ac.ukwrote:


 There is at least one context where the distinction must be
 preserved. Example:

  pnorm(1.5)
  # [1] 0.9331928
  pnorm(x=1.5)
  # Error in pnorm(x = 1.5) : unused argument(s) (x = 1.5)
  pnorm(x-1.5)
  # [1] 0.9331928
  x
  # [1] 1.5

 Ted.


 I would regard modifying a variable within the parameters of a function
call as pretty tasteless. What does:


 foo(x-2,x)
or
 foo(x,x-3)

do that couldn't be done clearer with two lines of code?

 Remember: 'eschew obfuscation'.

Barry

-- 
blog: http://geospaced.blogspot.com/
web: http://www.maths.lancs.ac.uk/~rowlings
web: http://www.rowlingson.com/
twitter: http://twitter.com/geospacedman
pics: http://www.flickr.com/photos/spacedman

[[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] advice/opinion on - vs = in teaching R

2010-01-15 Thread Ted Harding
On 15-Jan-10 08:14:04, Barry Rowlingson wrote:
 On Fri, Jan 15, 2010 at 6:57 AM, Ted Harding
 ted.hard...@manchester.ac.ukwrote:

 There is at least one context where the distinction must be
 preserved. Example:

  pnorm(1.5)
  # [1] 0.9331928
  pnorm(x=1.5)
  # Error in pnorm(x = 1.5) : unused argument(s) (x = 1.5)
  pnorm(x-1.5)
  # [1] 0.9331928
  x
  # [1] 1.5

 Ted.

 I would regard modifying a variable within the parameters of a
 function call as pretty tasteless. What does:
 
  foo(x-2,x)
 or
  foo(x,x-3)
 
 do that couldn't be done clearer with two lines of code?
 
  Remember: 'eschew obfuscation'.
 
 Barry

Tasteless or not, the language allows it to be done; and therefore
discussion of distinctions between ways of doing it is relevant to
Erin's question!

While I am at it, in addition to the above example, we can have

  x - 1.234
  sqrt(x=4)
  # [1] 2
  x
  # [1] 1.234

compared with (as in the first example):

  x - 1.234
  sqrt(x-4)
  # [1] 2
  x
  # [1] 4

There is a passage in ?- (which I don't completely understand)
which is also relevant to Erin's query about '=' vs '-':

  The operators '-' and '=' assign into the environment in
  which they are evaluated.  The operator '-' can be used
  anywhere, whereas the operator '=' is only allowed at the
  top level (e.g., in the complete expression typed at the
  command prompt) or as one of the subexpressions in a braced
  list of expressions.

(I'm not too clear about the scope of one of the subexpressions
in a braced list of expressions).

Ted.


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

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


Re: [R] advice/opinion on - vs = in teaching R

2010-01-15 Thread Deepayan Sarkar
On Fri, Jan 15, 2010 at 2:38 PM, Ted Harding
ted.hard...@manchester.ac.uk wrote:
 On 15-Jan-10 08:14:04, Barry Rowlingson wrote:
 On Fri, Jan 15, 2010 at 6:57 AM, Ted Harding
 ted.hard...@manchester.ac.ukwrote:

 There is at least one context where the distinction must be
 preserved. Example:

  pnorm(1.5)
  # [1] 0.9331928
  pnorm(x=1.5)
  # Error in pnorm(x = 1.5) : unused argument(s) (x = 1.5)
  pnorm(x-1.5)
  # [1] 0.9331928
  x
  # [1] 1.5

 Ted.

 I would regard modifying a variable within the parameters of a
 function call as pretty tasteless. What does:

  foo(x-2,x)
 or
  foo(x,x-3)

 do that couldn't be done clearer with two lines of code?

  Remember: 'eschew obfuscation'.

 Barry

 Tasteless or not, the language allows it to be done; and therefore
 discussion of distinctions between ways of doing it is relevant to
 Erin's question!

 While I am at it, in addition to the above example, we can have

  x - 1.234
  sqrt(x=4)
  # [1] 2
  x
  # [1] 1.234

 compared with (as in the first example):

  x - 1.234
  sqrt(x-4)
  # [1] 2
  x
  # [1] 4

 There is a passage in ?- (which I don't completely understand)
 which is also relevant to Erin's query about '=' vs '-':

  The operators '-' and '=' assign into the environment in
  which they are evaluated.  The operator '-' can be used
  anywhere, whereas the operator '=' is only allowed at the
  top level (e.g., in the complete expression typed at the
  command prompt) or as one of the subexpressions in a braced
  list of expressions.

 (I'm not too clear about the scope of one of the subexpressions
 in a braced list of expressions).

For example:

 x = xyplot(1~1)
 system.time(x = xyplot(1~1))
Error in system.time(x = xyplot(1 ~ 1)) :
  unused argument(s) (x = xyplot(1 ~ 1))
 system.time({ x = xyplot(1~1) })
   user  system elapsed
  0.008   0.000   0.005

Of course, - would not have had a problem. This is the most common
problem I personally have had using = for assignment (better
readability of - is also a huge plus).

-Deepayan

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

2010-01-15 Thread Bart Joosen

One way could be to first select only the unique ID's, sample this and then
select only the relevant records:

strQuery = SELECT ID from tblFoo;
IDs - sqlQuery(channel, strQuery)
sample.IDs - sample(IDs,10)
strQuery = paste(SELECT ID from tblFoo WHRE ID IN(, sample.IDs, );)
IDs - sqlQuery(channel, strQuery)

Bart



christiaan pauw-2 wrote:
 
 Hi Everybody
 
 Is there a way in which one can use the RPostgreSQL package to take a
 sample
 from a table in Postgres database without having to read the whole table
 into R
 
 regards
 Christiaan
 
   [[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.
 
 

-- 
View this message in context: 
http://n4.nabble.com/Sampling-from-a-Postgres-database-tp1014506p1014638.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] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Jim Lemon

On 01/15/2010 07:10 PM, Uli Kleinwechter wrote:

Dear all,

I'm looking for a way to replace NA's with 0 for a number of variables
which share the same ending and which constitute a subset of a data frame.

Say, for example, there is


data- data.frame(ax=c(1,2,3,NA,0) , bx=c(3,5,NA,5,1) ,

ay=c(5,NA,2,NA,0) , by=c(4,2,NA,2,1))

data

   ax bx ay by
1  1  3  5  4
2  2  5 NA  2
3  3 NA  2 NA
4 NA  5 NA  2
5  0  1  0  1

I wish to apply something like  //
//
/  data[is.na(data)]- 0/
//
but not to the entire data frame, rather only to the variables ending
with x.


Hi Uli,
How about:

data[,grep(x,names(data))][is.na(data[,grep(x,names(data))])]-0

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] advice/opinion on - vs = in teaching R

2010-01-15 Thread Ted Harding
On 15-Jan-10 09:29:16, Deepayan Sarkar wrote:
 On Fri, Jan 15, 2010 at 2:38 PM, Ted Harding
 ted.hard...@manchester.ac.uk wrote:
 On 15-Jan-10 08:14:04, Barry Rowlingson wrote:
 On Fri, Jan 15, 2010 at 6:57 AM, Ted Harding
 ted.hard...@manchester.ac.ukwrote:

 There is at least one context where the distinction must be
 preserved. Example:

 Â_pnorm(1.5)
 Â_# [1] 0.9331928
 Â_pnorm(x=1.5)
 Â_# Error in pnorm(x = 1.5) : unused argument(s) (x = 1.5)
 Â_pnorm(x-1.5)
 Â_# [1] 0.9331928
 Â_x
 Â_# [1] 1.5

 Ted.

 I would regard modifying a variable within the parameters of a
 function call as pretty tasteless. What does:

 Â_foo(x-2,x)
 or
 Â_foo(x,x-3)

 do that couldn't be done clearer with two lines of code?

 Â_Remember: 'eschew obfuscation'.

 Barry

 Tasteless or not, the language allows it to be done; and therefore
 discussion of distinctions between ways of doing it is relevant to
 Erin's question!

 While I am at it, in addition to the above example, we can have

 Â_x - 1.234
 Â_sqrt(x=4)
 Â_# [1] 2
 Â_x
 Â_# [1] 1.234

 compared with (as in the first example):

 Â_x - 1.234
 Â_sqrt(x-4)
 Â_# [1] 2
 Â_x
 Â_# [1] 4

 There is a passage in ?- (which I don't completely understand)
 which is also relevant to Erin's query about '=' vs '-':

 Â_The operators '-' and '=' assign into the environment in
 Â_which they are evaluated. Â_The operator '-' can be used
 Â_anywhere, whereas the operator '=' is only allowed at the
 Â_top level (e.g., in the complete expression typed at the
 Â_command prompt) or as one of the subexpressions in a braced
 Â_list of expressions.

 (I'm not too clear about the scope of one of the subexpressions
 in a braced list of expressions).
 
 For example:
 
 x = xyplot(1~1)
 system.time(x = xyplot(1~1))
 Error in system.time(x = xyplot(1 ~ 1)) :
   unused argument(s) (x = xyplot(1 ~ 1))
 system.time({ x = xyplot(1~1) })
user  system elapsed
   0.008   0.000   0.005
 
 Of course, - would not have had a problem. This is the most common
 problem I personally have had using = for assignment (better
 readability of - is also a huge plus).
 
 -Deepayan

Thanks for spelling out braced list, Deepayan.
And I have to agree with you about the readability of -.

Indeed, as summary advice to Erin, I wouild say use - except
in the specific context of assigning values to named parameters
in functions, to named elements of lists, and the like (where
use of = is mandatory anyway, or you won't get the desired
effect -- see below).

  list(x-1.234,y-2.345)
  # [[1]]
  # [1] 1.234
  # [[2]]
  # [1] 2.345

  list(x=1.234,y=2.345)
  # $x
  # [1] 1.234
  # $y
  # [1] 2.345

Ted.


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

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


[R] Remove part of string in colname and calculate mean for columns groups

2010-01-15 Thread Joel Fürstenberg-Hägg

Hi all,

 

I have two question. First, I wonder how to remove a part of the column names 
in a matrix? I would like to remove the _ACCX or _NAX part below. Is there 
a method where the _ as well as all characters after i can be removed?

 

 dim(exprdata)
[1]  88 512



 colnames(exprdata[,c(1:20)])
 [1] Akita_ACC1 Akita_ACC2 Akita_ACC3 Akita_ACC4 Alc.0_ACC1 
Alc.0_ACC2 Alc.0_ACC3
 [8] Alc.0_ACC4 Alc.0_ACC5 Bl.1_ACC1  Bl.1_ACC2  Bl.1_ACC3  
Bl.1_ACC4  Bla.1_ACC1
[15] Bla.1_ACC2 Bla.1_ACC3 Bla.1_ACC4 Blh.1_ACC1 Blh.1_ACC2 
Blh.1_ACC3

 

 

Secondly, I would like to calculate the mean of each column group in the 
matrix, for instance all columns beginning with Akita, and save all new 
columns as a new matrix. 

 

For instance, use:

 

 head(exprdata[,c(1:4)])
Akita_ACC1 Akita_ACC2 Akita_ACC3 Akita_ACC4
A15-101   6.668931 NA NA NA
A122001-101  10.562564  11.706395  11.608989   8.289093
A128001-101  14.946749   8.112625   8.176438  10.104254
A133001-101   5.186679   6.089870   4.119589   3.168841
A133003-101 NA NA  19.825480   2.587695
A134001-101   3.259402   4.835642   4.679607   4.490254

 

To get something like:

 

 Akita
A15-101   6.668931

A122001-101   10.54176  

A128001-101  10.10425
A133001-101   3.168841

A133003-101   2.587695 
A134001-101   4.490254

 

 

However, the column groups are of different sizes (3-10 columns) so I guess 
I'll need a method based on the column names.

 

Anyone who can help me?

 

Best regards,

 

Joel
  
_
Nya Windows 7 - Hitta en dator som passar dig! Mer information. 
http://windows.microsoft.com/shop
[[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] advice/opinion on - vs = in teaching R

2010-01-15 Thread Berwin A Turlach
G'day all,

On Fri, 15 Jan 2010 09:08:44 - (GMT)
(Ted Harding) ted.hard...@manchester.ac.uk wrote:

 On 15-Jan-10 08:14:04, Barry Rowlingson wrote:
  [...]
  I would regard modifying a variable within the parameters of a
  function call as pretty tasteless. What does:
  
   foo(x-2,x)
  or
   foo(x,x-3)
  
  do that couldn't be done clearer with two lines of code?

Depending on the definition of foo() more than two lines might be
necessary to clarify what this code is actually supposed to do. :)

   Remember: 'eschew obfuscation'.

Absolutely.

 Tasteless or not, the language allows it to be done; and therefore
 discussion of distinctions between ways of doing it is relevant to
 Erin's question!

And a full discussion of these examples would include to warn about the
side effects of lazy evaluation:

R rm(list=ls(all=TRUE))
R foo - function(x, y){
+   if(x  0 ) x else x + y}
R foo(2, x - 10)
[1] 2
R x
Error: object 'x' not found
R foo(-2, x - 10)
[1] 8
R x
[1] 10

Having said this, I often use plot(fm - lm(y ~ . , somedata)).

And, yes, students have complained that the code I gave them was not
working, that they got a strange error message and they promised that
they had typed exactly what I had written on the lab sheet.  On
checking, they had, of course, typed plot(fm = lm(y ~ . , somedata))

Cheers,

Berwin

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

2010-01-15 Thread Vladimir Pekar

Hi,

I would like to ask for advice about best statistics method for
my problem.
I was done questionnaire about headache.
My data are:
Y - frequency of symptoms occur - times per month in range 0..30
(where 30 is daily and zero for never)
and independent variables:
X1 - sex - category {M,F}
X2 - age - linear value
X3 - type of work {administrative, manual, ...} 
...

Which model is the best for my problem: to describe weight of
factors in equation chance_to_present_symptom ~ variables:
Y~X1+X2+X3

Y is not linear value with normal distribution.
Y describe something like chance of to have symptom.
I can't use linear regression, but something like logistic regression. 
Logistic is only for two (or more) Y value which is categorised not
linear.

Thank for any advice.

-vladimir-

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

2010-01-15 Thread vikrant

Can I save R graphs as a R objects ? IF yes then if I click this R object 
can I edit my chart as in Excel.
Please suggest your views
-- 
View this message in context: 
http://n4.nabble.com/Can-I-save-R-graphs-as-a-R-objects-tp1014621p1014621.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] Connecting R with MS SQL server 2005

2010-01-15 Thread vikrant

Is it possible to connect R with Ms SQL Server 2005 ? If Yes how to connect
it and can you please provide some tutorial for it?
-- 
View this message in context: 
http://n4.nabble.com/Connecting-R-with-MS-SQL-server-2005-tp1014643p1014643.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] Barplots in R

2010-01-15 Thread vikrant

Suppose I need to draw a Grouped bar plot with 100 values on the X axis. Now
my question is If I need to highlight suppose first three values by some
color say 'red' and also I need to highlight last 5 datavalues 
by some color say 'blue' and the rest of the data in between I need not
display. Is it possible? If yes How?
Could anyone explain
-- 
View this message in context: 
http://n4.nabble.com/Barplots-in-R-tp1014629p1014629.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] Latent Profile Analysis Package?

2010-01-15 Thread Jon Toledo

I´ve several packages for latent class analysis, but I was wondering if there 
is a package for continuos variables, which allows latent prfile analysis.
Thanks for your help in advance,
J Toledo
  
_


cial-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092
[[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] the sample() function

2010-01-15 Thread Federico Bonofiglio
hello R-Wizards! again i'm invoking your presence!!

since all the fuss about the paradoxes on a computer algorithm generating
caos or un-determinancy, i recently grew quite curious about the mechanism
underlying the procedure of NUMBER RADOMIZATION.

could anyone of you, masters, attach me the algorithm (or source code? is it
right?) behind the *sample()* function, so i can inspect in detail the
mechanism of this so gossiped radomization?

thank you, sincerely

federico bonofiglio,
student of statistics at
milano bicocca university,
italia

[[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] HTML translation problem in R-2.10.1

2010-01-15 Thread Jim Lemon

Hi everyone,
The problem was the result of my historical misbehavior of embedding 
links within certain font enhancements. This used to work, but no 
longer. Any of you package maintainers who find that your links are 
suddenly becoming literal text on the HTML help pages are likely to have 
the same problem. Solution - remove any \samp tags around the links. 
Thanks to Duncan who provided the necessary info.


New versions of the clinsig, crank, plotrix and prettyR packages will 
appear shortly.


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] Connecting R with MS SQL server 2005

2010-01-15 Thread vikrant


If anybody can provide me a link it will be very much helpful
-- 
View this message in context: 
http://n4.nabble.com/Connecting-R-with-MS-SQL-server-2005-tp1014643p1014669.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] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Johannes Signer
Hi,

this works aswell:

 for(i in 1:ncol(data)) data[is.na(data[,i]),i] - 0

i am sure there is way doing it with a member of the apply family, maybe
someone else has an idea.

Johannes

On Fri, Jan 15, 2010 at 9:51 PM, Jim Lemon j...@bitwrit.com.au wrote:

 On 01/15/2010 07:10 PM, Uli Kleinwechter wrote:

 Dear all,

 I'm looking for a way to replace NA's with 0 for a number of variables
 which share the same ending and which constitute a subset of a data frame.

 Say, for example, there is

  data- data.frame(ax=c(1,2,3,NA,0) , bx=c(3,5,NA,5,1) ,

 ay=c(5,NA,2,NA,0) , by=c(4,2,NA,2,1))

 data

   ax bx ay by
 1  1  3  5  4
 2  2  5 NA  2
 3  3 NA  2 NA
 4 NA  5 NA  2
 5  0  1  0  1

 I wish to apply something like  //
 //
 /  data[is.na(data)]- 0/
 //
 but not to the entire data frame, rather only to the variables ending
 with x.

  Hi Uli,
 How about:

 data[,grep(x,names(data))][is.na(data[,grep(x,names(data))])]-0

 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.


[[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] memDecompress and zlib compressed base64 encoded string

2010-01-15 Thread Johannes Graumann
Prof Brian Ripley wrote:

 I have zlib compressed strings (example is attached)
 
 What is that file? Not gzip compression:
 
 gannet% file compressed.txt
 compressed.txt: ASCII text, with very long lines
 
 since gzip uses a magic header that 'file' knows about.  And even if
 the header was stripped, such files are 8-bit and yours is ASCII.
 Try
 x - 'Johannes Graumann'
 xx - charToRaw(x)
 xxx - memCompress(xx, g)
 rawToChar(xxx)
 [1] x\x9c\xf3\xca\xcfH\xcc\xcbK-Vp/J,\xcd\0052\001:\n\006\x90
 
 to see what a real gzipped string looks like.
 
 and would like to decompress them using memDecompress ...

 I try this:
 connection - file(compressed.txt,r)
 compressed - readLines(connection)
I am dealing with mass spectrometric data in a XML file format (mzXML). The 
biggest part of the contained data is actual mass spectra that are base64 
encoded and optionally compressed using http://zlib.net (saving quite some 
storage space). When they are compressed I just get an XML node that looks 
like this
   peaksCONTENT OF THE ORIGINAL ATTACHMENT HERE/peaks
I would like to be able to decompress that string and thought that 
memDecompress was the right tool to do so ...

 You have not told us the 'at a minimum' information requested in the
 posting guide.  But you should not expect that to read a binary file,
 especially not in a MBCS locale.  We have readBin for that purpose.
I'm actually reading this in as a string from the XML file ...

 memDecompress(as.raw(compressed),type=g)
 
 I don't think you know what as.raw does: it does not convert bytes in
 a character string to raw (for which you need charToRaw).
 
 It is always a good idea to look at each stage of your computation:
 
 as.raw(compressed)
   [1] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00
 [26] 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
 00 00 00
Yup, that was plain stupid and trying to make memDecompress run at all 
(since handing it the character string also resulted in an error.

 sessionInfo() 
R version 2.10.1 (2009-12-14) 
x86_64-pc-linux-gnu 

locale:
 [1] LC_CTYPE=en_US.UTF-8  LC_NUMERIC=C 
 [3] LC_TIME=en_US.UTF-8   LC_COLLATE=en_US.UTF-8   
 [5] LC_MONETARY=en_US.UTF-8   LC_MESSAGES=en_US.UTF-8  
 [7] LC_PAPER=en_US.UTF-8  LC_NAME=en_US.UTF-8  
 [9] LC_ADDRESS=en_US.UTF-8LC_TELEPHONE=en_US.UTF-8 
[11] LC_MEASUREMENT=en_US.UTF-8LC_IDENTIFICATION=en_US.UTF-8

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

other attached packages:
[1] rkward_0.5.1

loaded via a namespace (and not attached):
[1] tools_2.10.1

Thanks for any further hints, Joh

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] estimating rho of Poisson distributed data

2010-01-15 Thread Titus von der Malsburg
Mean and variance of Poisson distributed data are specified by \rho.
How can I estimate \rho for a set of measurements in R?

Many thanks!

  Titus

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] advice/opinion on - vs = in teaching R

2010-01-15 Thread Peter Dalgaard
Barry Rowlingson wrote:
 On Fri, Jan 15, 2010 at 3:45 AM, Erin Hodgess erinm.hodg...@gmail.comwrote:
 
 Hi R People:

 I'm teaching a statistical computing class using R starting next week
 (yay!) and I have an opinion type question, please.

 I'm old school and use - in an assignment.


  You call that 'old school'?? I still use ' x_1'! Of course ESS turns the
 underscore into '-' magically.
 
  Perhaps these guys should redo their tests with slightly different syntax:
 
 http://www.cs.mdx.ac.uk/research/PhDArea/saeed/paper1.pdf
 
 Barry
 

I do like their experimental design:

In a bizarre event which one of the authors insists was planned, and
the other maintains was a really stupid idea that just happened to work,
the test was first administered to about 30 students on a

(Like in the sense of being amused, of course)

-p


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

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


Re: [R] Latent Profile Analysis Package?

2010-01-15 Thread Ingmar Visser
Jon,
There are packages that fit mixtures of multivariate normals (mclust) and in
flexmix
one can also model multiple measures (with local independence assumption).
hth, Ingmar

On Fri, Jan 15, 2010 at 11:08 AM, Jon Toledo tintin...@hotmail.com wrote:


 I扉e several packages for latent class analysis, but I was wondering if
 there is a package for continuos variables, which allows latent prfile
 analysis.
 Thanks for your help in advance,
 J Toledo

 _


 cial-network-basics.aspx?ocid=PID23461::T:WLMTAGL:ON:WL:en-xm:SI_SB_1:092
[[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] Can I save R graphs as a R objects

2010-01-15 Thread Paul Hiemstra

vikrant wrote:
Can I save R graphs as a R objects ? IF yes then if I click this R object 
can I edit my chart as in Excel.

Please suggest your views
  
When you use the graphics functions from the lattice package (e.g. 
xyplot) you can save them to a file (see ?save) because it creates an 
object that represents the graph. When using the standard plot system I 
think this is not possible. But if you have the original data and an R 
script to make the graph, you don't need to save the graph explicitly. 
When processing the data for the graph takes a long time, you can run 
the script to just before making the graph and save all the appropriate 
objects to disk. Next time you only need to load your data (see ?load) 
and make the plot.


cheers,
Paul

--
Drs. Paul Hiemstra
Department of Physical Geography
Faculty of Geosciences
University of Utrecht
Heidelberglaan 2
P.O. Box 80.115
3508 TC Utrecht
Phone:  +3130 274 3113 Mon-Tue
Phone:  +3130 253 5773 Wed-Fri
http://intamap.geo.uu.nl/~paul

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

2010-01-15 Thread K. Elo
Hi!

Let's suppose the values for the x axis are stored in 'values'.

barplot(values, col=c(rep(Red,3),rep(1,length(values)-8),rep(Blue,5)))

HTH,
Kimmo

vikrant kirjoitti:
 Suppose I need to draw a Grouped bar plot with 100 values on the X axis. Now
 my question is If I need to highlight suppose first three values by some
 color say 'red' and also I need to highlight last 5 datavalues 
 by some color say 'blue' and the rest of the data in between I need not
 display. Is it possible? If yes How?
 Could anyone explain

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Connecting R with MS SQL server 2005

2010-01-15 Thread Dieter Menne



vikrant wrote:
 
 Is it possible to connect R with Ms SQL Server 2005 ? If Yes how to
 connect it and can you please provide some tutorial for it?
 

It's easiest using RODBC. Using Control Panel/Administrator/Data Sources
(Free translation from German, might be slightly off), create a source using
the SQL Server Native Client; you might have to install that client from the
MS site, if it is not there.

Then, connect to that source and issue a SELECT...

Dieter


-- 
View this message in context: 
http://n4.nabble.com/Connecting-R-with-MS-SQL-server-2005-tp1014643p1014705.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] Can I save R graphs as a R objects

2010-01-15 Thread Henrique Dallazuanna
You can use the recordPlot function from base package also

On Fri, Jan 15, 2010 at 7:26 AM, vikrant vikrant.shi...@tcs.com wrote:

 Can I save R graphs as a R objects ? IF yes then if I click this R object
 can I edit my chart as in Excel.
 Please suggest your views
 --
 View this message in context: 
 http://n4.nabble.com/Can-I-save-R-graphs-as-a-R-objects-tp1014621p1014621.html
 Sent from the R help mailing list archive at Nabble.com.

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




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

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


Re: [R] Connecting R with MS SQL server 2005

2010-01-15 Thread Uwe Ligges



On 15.01.2010 11:23, vikrant wrote:



If anybody can provide me a link it will be very much helpful


See package RODBC.


Uwe Ligges

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


Re: [R] Can I save R graphs as a R objects

2010-01-15 Thread Rainer M Krug
On Fri, Jan 15, 2010 at 11:26 AM, vikrant vikrant.shi...@tcs.com wrote:


 Can I save R graphs as a R objects ?


I have seen that feature in the rkward GUI (which is by the way the BEST GUI
I have seen for a long time!), but I haven't played with that feature a lot,
so I can not comment on your second question.

By the way: rkward has SOME editing functionality for graphs, after they are
created (GUI type)

Cheers,

Rainer


IF yes then if I click this R object
 can I edit my chart as in Excel.
 Please suggest your views
 --
 View this message in context:
 http://n4.nabble.com/Can-I-save-R-graphs-as-a-R-objects-tp1014621p1014621.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.




-- 
NEW GERMAN FAX NUMBER!!!

Rainer M. Krug, PhD (Conservation Ecology, SUN), MSc (Conservation Biology,
UCT), Dipl. Phys. (Germany)

Centre of Excellence for Invasion Biology
Natural Sciences Building
Office Suite 2039
Stellenbosch University
Main Campus, Merriman Avenue
Stellenbosch
South Africa

Cell:   +27 - (0)83 9479 042
Fax:+27 - (0)86 516 2782
Fax:+49 - (0)321 2125 2244
email:  rai...@krugs.de

Skype:  RMkrug
Google: r.m.k...@gmail.com

[[alternative HTML version deleted]]

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


Re: [R] select: bad file descriptor in the multicore package

2010-01-15 Thread Uwe Ligges



On 13.01.2010 05:43, Hao Cen wrote:

Hi,

I wonder anyone knows what causes the error message select: bad file
descriptor in the multicore package. This error sometimes occurs and
sometimes doesn't. I couldn't find any documentation on this error about
this package.



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


Please try to give relevant information or start debugging yourself.

Uwe Ligges




thanks

Jeff

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Remove part of string in colname and calculate mean for columns groups

2010-01-15 Thread Dieter Menne



Joel Fürstenberg-Hägg wrote:
 
 
 
 I have two question. First, I wonder how to remove a part of the column
 names in a matrix? I would like to remove the _ACCX or _NAX part
 below. Is there a method where the _ as well as all characters after i
 can be removed?
 
 Secondly, I would like to calculate the mean of each column group in the
 matrix, for instance all columns beginning with Akita, and save all new
 columns as a new matrix. 
  
 

If you do that in the example you gave, duplicate column names would be the
result, but let's assume that was a typo.

# Simplify names
data = data.frame(Akita.0_ACC1=1:2,Akita.1_ACC2=2:3,Alc.0_ACC1=3:4)
names(data) = sub(_.*,,names(data))
# Make a new data frame with the Akitas only
dataAkita = data[,grep(Akita,names(data))]

To do the averaging, check the examples in package plyr. 

Dieter






-- 
View this message in context: 
http://n4.nabble.com/Remove-part-of-string-in-colname-and-calculate-mean-for-columns-groups-tp1014652p1014724.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] processing all files with certain extension in a directory

2010-01-15 Thread Albert Vilella
Hi all,

I'm trying to process all files with a certain extension *.ext in a
directory like this:

 R --slave --args /my/dir  dir_plot.r

where I then I want to do something like:

myarg - commandArgs()
inputdir - myarg[length(myarg)]
print(inputdir)
for file with extension *.ext in inputdir
do
  data = process.data(file)
  outfile = paste(file,.png,sep=)
  png(outfile,width=3200,height=2400)
  do.a.plot(data)
  dev.off()
done
q()

How can I do the file looping bit?

Thanks in advance,

Cheers,

Albert.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] processing all files with certain extension in a directory

2010-01-15 Thread Remko Duursma
Albert,

try something like this:

extfiles - list.files(pattern=.ext)
for(f in extfiles){

   process.data(f)
   #etc

}


greetings,
Remko

-
Remko Duursma
Post-Doctoral Fellow

Centre for Plants and the Environment
University of Western Sydney
Hawkesbury Campus
Richmond NSW 2753

Dept of Biological Science
Macquarie University
North Ryde NSW 2109
Australia

Mobile: +61 (0)422 096908
www.remkoduursma.com



On Fri, Jan 15, 2010 at 10:43 PM, Albert Vilella avile...@gmail.com wrote:
 Hi all,

 I'm trying to process all files with a certain extension *.ext in a
 directory like this:

 R --slave --args /my/dir  dir_plot.r

 where I then I want to do something like:

 myarg - commandArgs()
 inputdir - myarg[length(myarg)]
 print(inputdir)
 for file with extension *.ext in inputdir
 do
  data = process.data(file)
  outfile = paste(file,.png,sep=)
  png(outfile,width=3200,height=2400)
  do.a.plot(data)
  dev.off()
 done
 q()

 How can I do the file looping bit?

 Thanks in advance,

 Cheers,

 Albert.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] processing all files with certain extension in a directory

2010-01-15 Thread Benilton Carvalho
theFiles - list.files(inputdir, full=T, pattern=\\.[eE][xX][tT]$)
for (file in theFiles){
...
}


On Fri, Jan 15, 2010 at 11:43 AM, Albert Vilella avile...@gmail.com wrote:
 Hi all,

 I'm trying to process all files with a certain extension *.ext in a
 directory like this:

 R --slave --args /my/dir  dir_plot.r

 where I then I want to do something like:

 myarg - commandArgs()
 inputdir - myarg[length(myarg)]
 print(inputdir)
 for file with extension *.ext in inputdir
 do
  data = process.data(file)
  outfile = paste(file,.png,sep=)
  png(outfile,width=3200,height=2400)
  do.a.plot(data)
  dev.off()
 done
 q()

 How can I do the file looping bit?

 Thanks in advance,

 Cheers,

 Albert.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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 delete matrix rows based on NA frequency?

2010-01-15 Thread Joel Fürstenberg-Hägg

Hi all,

 

I would like to remove rows from a matrix, based on the frequency of missing 
values. If there are more than 10 % missing values, the row should be deleted.

 

I use the following to calculate the frequencies, thereby getting a new matrix 
with the frequencies:

 

freqNA=rowMeans(is.na(exprdata))

 

But is there a shorter way to remove the rows based on (1-freqNA)0.1 than 
looping through the whole matrix using a for loop?

 

 

All the best,

 

Joel
  
_
Hitta kärleken i vinter!
http://dejting.se.msn.com/channel/index.aspx?trackingid=1002952
[[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 delete matrix rows based on NA frequency?

2010-01-15 Thread Remko Duursma
Joel,

try this:

# sample matrix
m - matrix(sample(c(1:10, NA),150,replace=T),byrow=T,ncol=15)

# nr of missing values per row
nacounts - apply(m, 1, function(x)length(x[is.na(x)]))

# new matrix
newm - m[nacounts/ncol(m)  0.1,]




greetings,
Remko


-
Remko Duursma
Post-Doctoral Fellow

Centre for Plants and the Environment
University of Western Sydney
Hawkesbury Campus
Richmond NSW 2753

Dept of Biological Science
Macquarie University
North Ryde NSW 2109
Australia

Mobile: +61 (0)422 096908
www.remkoduursma.com



2010/1/15 Joel Fürstenberg-Hägg joel_furstenberg_h...@hotmail.com:

 Hi all,



 I would like to remove rows from a matrix, based on the frequency of missing 
 values. If there are more than 10 % missing values, the row should be deleted.



 I use the following to calculate the frequencies, thereby getting a new 
 matrix with the frequencies:



 freqNA=rowMeans(is.na(exprdata))



 But is there a shorter way to remove the rows based on (1-freqNA)0.1 than 
 looping through the whole matrix using a for loop?





 All the best,



 Joel

 _
 Hitta kärleken i vinter!
 http://dejting.se.msn.com/channel/index.aspx?trackingid=1002952
        [[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 delete matrix rows based on NA frequency?

2010-01-15 Thread Henrique Dallazuanna
Try this:

m[prop.table(rowSums(is.na(m)))  0.1,]

2010/1/15 Joel Fürstenberg-Hägg joel_furstenberg_h...@hotmail.com:

 Hi all,



 I would like to remove rows from a matrix, based on the frequency of missing 
 values. If there are more than 10 % missing values, the row should be deleted.



 I use the following to calculate the frequencies, thereby getting a new 
 matrix with the frequencies:



 freqNA=rowMeans(is.na(exprdata))



 But is there a shorter way to remove the rows based on (1-freqNA)0.1 than 
 looping through the whole matrix using a for loop?





 All the best,



 Joel

 _
 Hitta kärleken i vinter!
 http://dejting.se.msn.com/channel/index.aspx?trackingid=1002952
        [[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.





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

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


Re: [R] advice/opinion on - vs = in teaching R

2010-01-15 Thread Duncan Murdoch

Barry Rowlingson wrote:

On Fri, Jan 15, 2010 at 6:57 AM, Ted Harding
ted.hard...@manchester.ac.ukwrote:

  

There is at least one context where the distinction must be
preserved. Example:

 pnorm(1.5)
 # [1] 0.9331928
 pnorm(x=1.5)
 # Error in pnorm(x = 1.5) : unused argument(s) (x = 1.5)
 pnorm(x-1.5)
 # [1] 0.9331928
 x
 # [1] 1.5

Ted.




 I would regard modifying a variable within the parameters of a function
call as pretty tasteless. What does:


 foo(x-2,x)
or
 foo(x,x-3)

do that couldn't be done clearer with two lines of code?
  


The most common use I see that I like is within a conditional test like

if (  !is.null(x - get(x, somehow))  length(x) == 1) { dosomething }

The x variable is only used for the test, but since it is used twice 
there, the assignment saves getting it twice.  You could expand it to 
two lines


x - get(x, somehow)
if ( !is.null(x)  length(x) == 1) { dosomething }

but I find that a tiny bit harder to read. 

On the other hand, I would never use the examples you gave, because I'd 
have no idea what the value of x would be, since it depends on the order 
of evaluation of the arguments.  In R, I don't even know for sure if the 
assignment would be evaluated at all, let alone before the x argument.


Duncan Murdoch

 Remember: 'eschew obfuscation'.

Barry




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

2010-01-15 Thread ONKELINX, Thierry
Dear Vladimir,

You can use a logistic regression. First define Y0 as 30 - Y. Then Y is
the number of days with headache and Y0 the number of days without.
Then the model looks like: glm(cbind(Y, Y0) ~ X1 + X2 + X3, family =
binomial)

HTH,

Thierry 




ir. Thierry Onkelinx
Instituut voor natuur- en bosonderzoek
team Biometrie  Kwaliteitszorg
Gaverstraat 4
9500 Geraardsbergen
Belgium

Research Institute for Nature and Forest
team Biometrics  Quality Assurance
Gaverstraat 4
9500 Geraardsbergen
Belgium

tel. + 32 54/436 185
thierry.onkel...@inbo.be
www.inbo.be

To call in the statistician after the experiment is done may be no more
than asking him to perform a post-mortem examination: he may be able to
say what the experiment died of.
~ Sir Ronald Aylmer Fisher

The plural of anecdote is not data.
~ Roger Brinner

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

-Oorspronkelijk bericht-
Van: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org]
Namens Vladimir Pekar
Verzonden: vrijdag 15 januari 2010 11:26
Aan: r-help@r-project.org
Onderwerp: [R] Best method


Hi,

I would like to ask for advice about best statistics method for my
problem.
I was done questionnaire about headache.
My data are:
Y - frequency of symptoms occur - times per month in range 0..30
(where 30 is daily and zero for never) and independent variables:
X1 - sex - category {M,F}
X2 - age - linear value
X3 - type of work {administrative, manual, ...} ...

Which model is the best for my problem: to describe weight of factors
in equation chance_to_present_symptom ~ variables:
Y~X1+X2+X3

Y is not linear value with normal distribution.
Y describe something like chance of to have symptom.
I can't use linear regression, but something like logistic regression. 
Logistic is only for two (or more) Y value which is categorised not
linear.

Thank for any advice.

-vladimir-

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

Druk dit bericht a.u.b. niet onnodig af.
Please do not print this message unnecessarily.

Dit bericht en eventuele bijlagen geven enkel de visie van de schrijver weer 
en binden het INBO onder geen enkel beding, zolang dit bericht niet bevestigd is
door een geldig ondertekend document. The views expressed in  this message 
and any annex are purely those of the writer and may not be regarded as stating 
an official position of INBO, as long as the message is not confirmed by a duly 
signed document.

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

2010-01-15 Thread Michael Friendly

I have a list of vectors, all forced to be the same length:

testlist - list(
   shape=c(0, 0, 2),
 cell.fill=c(red,blue,green),
   back.fill=rep(white,3),
   scale.max=rep(100,3)
   )
 str(testlist)
List of 4
$ shape: num [1:3] 0 0 2
$ cell.fill: chr [1:3] red blue green
$ back.fill: chr [1:3] white white white
$ scale.max: num [1:3] 100 100 100


I need to 'transpose' them into a list of lists with named values like so:

wanted - list(
   list(shape=0, cell.fill=red, back.fill=white, scale.max=100),
   list(shape=0, cell.fill=blue, back.fill=white, scale.max=100),
   list(shape=2, cell.fill=green, back.fill=white, scale.max=100)
   )
 str(wanted)
List of 3
$ :List of 4
 ..$ shape: num 0
 ..$ cell.fill: chr red
 ..$ back.fill: chr white
 ..$ scale.max: num 3
$ :List of 4
 ..$ shape: num 0
 ..$ cell.fill: chr blue
 ..$ back.fill: chr white
 ..$ scale.max: num 3
$ :List of 4
 ..$ shape: num 2
 ..$ cell.fill: chr green
 ..$ back.fill: chr white
 ..$ scale.max: num 3


How can I do this in general?

--
Michael Friendly Email: friendly AT yorku DOT ca 
Professor, Psychology Dept.

York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA

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


Re: [R] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Uli Kleinwechter
Jim Lemon schrieb:
 On 01/15/2010 07:10 PM, Uli Kleinwechter wrote:
 Dear all,

 I'm looking for a way to replace NA's with 0 for a number of variables
 which share the same ending and which constitute a subset of a data
 frame.

 Say, for example, there is

 data- data.frame(ax=c(1,2,3,NA,0) , bx=c(3,5,NA,5,1) ,
 ay=c(5,NA,2,NA,0) , by=c(4,2,NA,2,1))
 data
ax bx ay by
 1  1  3  5  4
 2  2  5 NA  2
 3  3 NA  2 NA
 4 NA  5 NA  2
 5  0  1  0  1

 I wish to apply something like  //
 //
 /  data[is.na(data)]- 0/
 //
 but not to the entire data frame, rather only to the variables ending
 with x.

 Hi Uli,
 How about:

 data[,grep(x,names(data))][is.na(data[,grep(x,names(data))])]-0

 Jim

Hi Jim,

thanks a lot. I'm just afraid that grep matches any occurence of x in
the variable name. So variables which would contain x at any position,
not necessarily only at the last one would be selected, as well. To
refine my example (sorry for having been so imprecise before...):

 data- data.frame(ax=c(1,2,3,NA,0) , bx=c(3,5,NA,5,1)
,ay=c(5,NA,2,NA,0) , xy=c(4,2,NA,2,1))
 data
  ax bx ay xy
1  1  3  5  4
2  2  5 NA  2
3  3 NA  2 NA
4 NA  5 NA  2
5  0  1  0  1

The task, again, would be to replace NA's with 0 in ax and bx, but
not in ay and xy

Best,

Uli

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

2010-01-15 Thread jim holtman
Does this do it:

 testlist - list(
+   shape=c(0, 0, 2),
+  cell.fill=c(red,blue,green),
+   back.fill=rep(white,3),
+   scale.max=rep(100,3)
+   )

 wanted - lapply(seq(length(testlist[[1]])), function(x){
+ # iterate for each element of the list
+ result - lapply(names(testlist), function(.name){
+ list(testlist[[.name]][x])
+ })
+ names(result) - names(testlist)
+ result
+ })
 dput(wanted)
list(structure(list(shape = list(0), cell.fill = list(red),
back.fill = list(white), scale.max = list(100)), .Names = c(shape,
cell.fill, back.fill, scale.max)), structure(list(shape = list(
0), cell.fill = list(blue), back.fill = list(white),
scale.max = list(100)), .Names = c(shape, cell.fill,
back.fill, scale.max)), structure(list(shape = list(2), cell.fill =
list(
green), back.fill = list(white), scale.max = list(100)), .Names =
c(shape,
cell.fill, back.fill, scale.max)))




On Fri, Jan 15, 2010 at 8:09 AM, Michael Friendly frien...@yorku.ca wrote:

 I have a list of vectors, all forced to be the same length:

 testlist - list(
   shape=c(0, 0, 2),
  cell.fill=c(red,blue,green),
   back.fill=rep(white,3),
   scale.max=rep(100,3)
   )
  str(testlist)
 List of 4
 $ shape: num [1:3] 0 0 2
 $ cell.fill: chr [1:3] red blue green
 $ back.fill: chr [1:3] white white white
 $ scale.max: num [1:3] 100 100 100
 

 I need to 'transpose' them into a list of lists with named values like so:

 wanted - list(
   list(shape=0, cell.fill=red, back.fill=white, scale.max=100),
   list(shape=0, cell.fill=blue, back.fill=white, scale.max=100),
   list(shape=2, cell.fill=green, back.fill=white, scale.max=100)
   )
  str(wanted)
 List of 3
 $ :List of 4
  ..$ shape: num 0
  ..$ cell.fill: chr red
  ..$ back.fill: chr white
  ..$ scale.max: num 3
 $ :List of 4
  ..$ shape: num 0
  ..$ cell.fill: chr blue
  ..$ back.fill: chr white
  ..$ scale.max: num 3
 $ :List of 4
  ..$ shape: num 2
  ..$ cell.fill: chr green
  ..$ back.fill: chr white
  ..$ scale.max: num 3
 

 How can I do this in general?

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

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




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

What is the problem that you are trying to solve?

[[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] call R with un expression (String)?

2010-01-15 Thread Jiiindo

Hello all,
I want to call R from java. And I have a expression in Java as a String,
example : (variable 1 + variable 2)* variable 3 and i want R calculate this
expression. How can I do?
ex: 
Java
-int x1,x2;
-float x3;
-String s=(  x1.toString()+x2.toString()   )  *   x3.toString();
R:
calculate expression s and return in to Java?

Thanks 
Jin
-- 
View this message in context: 
http://n4.nabble.com/call-R-with-un-expression-String-tp1014832p1014832.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] Can I save R graphs as a R objects

2010-01-15 Thread Liviu Andronic
On 1/15/10, vikrant vikrant.shi...@tcs.com wrote:
  can I edit my chart as in Excel.

Sort of, using playwith. You can always try to place the the plot call
inside playwith(). For example,
require(playwith)
playwith(plot(1:10))

Liviu

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

2010-01-15 Thread jim holtman
fingers too fast; didn't need the enclosing 'list':

 testlist - list(
+   shape=c(0, 0, 2),
+  cell.fill=c(red,blue,green),
+   back.fill=rep(white,3),
+   scale.max=rep(100,3)
+   )

 wanted - lapply(seq(length(testlist[[1]])), function(x){
+ # iterate for each element of the list
+ result - lapply(names(testlist), function(.name){
+ testlist[[.name]][x]
+ })
+ names(result) - names(testlist)
+ result
+ })
 dput(wanted)
list(structure(list(shape = 0, cell.fill = red, back.fill = white,
scale.max = 100), .Names = c(shape, cell.fill, back.fill,
scale.max)), structure(list(shape = 0, cell.fill = blue,
back.fill = white, scale.max = 100), .Names = c(shape,
cell.fill, back.fill, scale.max)), structure(list(shape = 2,
cell.fill = green, back.fill = white, scale.max = 100), .Names =
c(shape,
cell.fill, back.fill, scale.max)))



On Fri, Jan 15, 2010 at 8:09 AM, Michael Friendly frien...@yorku.ca wrote:

 I have a list of vectors, all forced to be the same length:

 testlist - list(
   shape=c(0, 0, 2),
  cell.fill=c(red,blue,green),
   back.fill=rep(white,3),
   scale.max=rep(100,3)
   )
  str(testlist)
 List of 4
 $ shape: num [1:3] 0 0 2
 $ cell.fill: chr [1:3] red blue green
 $ back.fill: chr [1:3] white white white
 $ scale.max: num [1:3] 100 100 100
 

 I need to 'transpose' them into a list of lists with named values like so:

 wanted - list(
   list(shape=0, cell.fill=red, back.fill=white, scale.max=100),
   list(shape=0, cell.fill=blue, back.fill=white, scale.max=100),
   list(shape=2, cell.fill=green, back.fill=white, scale.max=100)
   )
  str(wanted)
 List of 3
 $ :List of 4
  ..$ shape: num 0
  ..$ cell.fill: chr red
  ..$ back.fill: chr white
  ..$ scale.max: num 3
 $ :List of 4
  ..$ shape: num 0
  ..$ cell.fill: chr blue
  ..$ back.fill: chr white
  ..$ scale.max: num 3
 $ :List of 4
  ..$ shape: num 2
  ..$ cell.fill: chr green
  ..$ back.fill: chr white
  ..$ scale.max: num 3
 

 How can I do this in general?

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

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




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

What is the problem that you are trying to solve?

[[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] transposing a list of vectors

2010-01-15 Thread Henrique Dallazuanna
Try this:

#'1) But apply converts all to 'character'
apply(as.data.frame(testlist), 1, as.list)

#2)
lapply(split(x - as.data.frame(testlist), 1:nrow(x)), as.list)

On Fri, Jan 15, 2010 at 11:09 AM, Michael Friendly frien...@yorku.ca wrote:
 I have a list of vectors, all forced to be the same length:

 testlist - list(
   shape=c(0, 0, 2),
  cell.fill=c(red,blue,green),
   back.fill=rep(white,3),
   scale.max=rep(100,3)
   )
 str(testlist)
 List of 4
 $ shape    : num [1:3] 0 0 2
 $ cell.fill: chr [1:3] red blue green
 $ back.fill: chr [1:3] white white white
 $ scale.max: num [1:3] 100 100 100


 I need to 'transpose' them into a list of lists with named values like so:

 wanted - list(
   list(shape=0, cell.fill=red, back.fill=white, scale.max=100),
   list(shape=0, cell.fill=blue, back.fill=white, scale.max=100),
   list(shape=2, cell.fill=green, back.fill=white, scale.max=100)
   )
 str(wanted)
 List of 3
 $ :List of 4
  ..$ shape    : num 0
  ..$ cell.fill: chr red
  ..$ back.fill: chr white
  ..$ scale.max: num 3
 $ :List of 4
  ..$ shape    : num 0
  ..$ cell.fill: chr blue
  ..$ back.fill: chr white
  ..$ scale.max: num 3
 $ :List of 4
  ..$ shape    : num 2
  ..$ cell.fill: chr green
  ..$ back.fill: chr white
  ..$ scale.max: num 3


 How can I do this in general?

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

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




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

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


Re: [R] Replacing NAs with 0 for variables with the same ending

2010-01-15 Thread Henrique Dallazuanna
In grep use: grep(x$, names(data)).

'$' matchs 'x' in the end of string

On Fri, Jan 15, 2010 at 11:14 AM, Uli Kleinwechter
u.kleinwech...@uni-hohenheim.de wrote:
 Jim Lemon schrieb:
 On 01/15/2010 07:10 PM, Uli Kleinwechter wrote:
 Dear all,

 I'm looking for a way to replace NA's with 0 for a number of variables
 which share the same ending and which constitute a subset of a data
 frame.

 Say, for example, there is

 data- data.frame(ax=c(1,2,3,NA,0) , bx=c(3,5,NA,5,1) ,
 ay=c(5,NA,2,NA,0) , by=c(4,2,NA,2,1))
 data
    ax bx ay by
 1  1  3  5  4
 2  2  5 NA  2
 3  3 NA  2 NA
 4 NA  5 NA  2
 5  0  1  0  1

 I wish to apply something like  //
 //
 /  data[is.na(data)]- 0/
 //
 but not to the entire data frame, rather only to the variables ending
 with x.

 Hi Uli,
 How about:

 data[,grep(x,names(data))][is.na(data[,grep(x,names(data))])]-0

 Jim

 Hi Jim,

 thanks a lot. I'm just afraid that grep matches any occurence of x in
 the variable name. So variables which would contain x at any position,
 not necessarily only at the last one would be selected, as well. To
 refine my example (sorry for having been so imprecise before...):

 data- data.frame(ax=c(1,2,3,NA,0) , bx=c(3,5,NA,5,1)
 ,ay=c(5,NA,2,NA,0) , xy=c(4,2,NA,2,1))
 data
  ax bx ay xy
 1  1  3  5  4
 2  2  5 NA  2
 3  3 NA  2 NA
 4 NA  5 NA  2
 5  0  1  0  1

 The task, again, would be to replace NA's with 0 in ax and bx, but
 not in ay and xy

 Best,

 Uli

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




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

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


Re: [R] transposing a list of vectors

2010-01-15 Thread Gabor Grothendieck
This gives the result you asked for:

DF - as.data.frame(testlist)
lapply(split(DF, 1:nrow(DF)), unclass)

although it might be good enough to just do this depending on what you need:

DF - as.data.frame(testlist)
split(DF, 1:nrow(DF)


On Fri, Jan 15, 2010 at 8:09 AM, Michael Friendly frien...@yorku.ca wrote:
 I have a list of vectors, all forced to be the same length:

 testlist - list(
   shape=c(0, 0, 2),
  cell.fill=c(red,blue,green),
   back.fill=rep(white,3),
   scale.max=rep(100,3)
   )
 str(testlist)
 List of 4
 $ shape    : num [1:3] 0 0 2
 $ cell.fill: chr [1:3] red blue green
 $ back.fill: chr [1:3] white white white
 $ scale.max: num [1:3] 100 100 100


 I need to 'transpose' them into a list of lists with named values like so:

 wanted - list(
   list(shape=0, cell.fill=red, back.fill=white, scale.max=100),
   list(shape=0, cell.fill=blue, back.fill=white, scale.max=100),
   list(shape=2, cell.fill=green, back.fill=white, scale.max=100)
   )
 str(wanted)
 List of 3
 $ :List of 4
  ..$ shape    : num 0
  ..$ cell.fill: chr red
  ..$ back.fill: chr white
  ..$ scale.max: num 3
 $ :List of 4
  ..$ shape    : num 0
  ..$ cell.fill: chr blue
  ..$ back.fill: chr white
  ..$ scale.max: num 3
 $ :List of 4
  ..$ shape    : num 2
  ..$ cell.fill: chr green
  ..$ back.fill: chr white
  ..$ scale.max: num 3


 How can I do this in general?

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

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 NAs with 0 for variables with the same ending

2010-01-15 Thread Olivier CROUZET



Uli Kleinwechter a écrit :



data[,grep(x,names(data))][is.na(data[,grep(x,names(data))])]-0



thanks a lot. I'm just afraid that grep matches any occurence of x in
the variable name. So variables which would contain x at any position,
not necessarily only at the last one would be selected, as well. To
refine my example (sorry for having been so imprecise before...):


Replacing x with x$ in grep calls should do the job...

Olivier.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 NAs with 0 for variables with the same ending

2010-01-15 Thread Uli Kleinwechter
That's it, thanks a lot to all of you!

Uli


Henrique Dallazuanna schrieb:
 In grep use: grep(x$, names(data)).

 '$' matchs 'x' in the end of string

 On Fri, Jan 15, 2010 at 11:14 AM, Uli Kleinwechter
 u.kleinwech...@uni-hohenheim.de wrote:
   
 Jim Lemon schrieb:
 
 On 01/15/2010 07:10 PM, Uli Kleinwechter wrote:
   
 Dear all,

 I'm looking for a way to replace NA's with 0 for a number of variables
 which share the same ending and which constitute a subset of a data
 frame.

 Say, for example, there is

 
 data- data.frame(ax=c(1,2,3,NA,0) , bx=c(3,5,NA,5,1) ,
   
 ay=c(5,NA,2,NA,0) , by=c(4,2,NA,2,1))
 
 data
   
ax bx ay by
 1  1  3  5  4
 2  2  5 NA  2
 3  3 NA  2 NA
 4 NA  5 NA  2
 5  0  1  0  1

 I wish to apply something like  //
 //
 /  data[is.na(data)]- 0/
 //
 but not to the entire data frame, rather only to the variables ending
 with x.

 
 Hi Uli,
 How about:

 data[,grep(x,names(data))][is.na(data[,grep(x,names(data))])]-0

 Jim

   
 Hi Jim,

 thanks a lot. I'm just afraid that grep matches any occurence of x in
 the variable name. So variables which would contain x at any position,
 not necessarily only at the last one would be selected, as well. To
 refine my example (sorry for having been so imprecise before...):

 
 data- data.frame(ax=c(1,2,3,NA,0) , bx=c(3,5,NA,5,1)
   
 ,ay=c(5,NA,2,NA,0) , xy=c(4,2,NA,2,1))
 
 data
   
  ax bx ay xy
 1  1  3  5  4
 2  2  5 NA  2
 3  3 NA  2 NA
 4 NA  5 NA  2
 5  0  1  0  1

 The task, again, would be to replace NA's with 0 in ax and bx, but
 not in ay and xy

 Best,

 Uli

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/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] FW: Problems connecting with MySQL using odbcDriverConnect (RODBC package) on Linux

2010-01-15 Thread Orvalho Augusto
Ok.

Caveman


On Thu, Jan 14, 2010 at 5:19 PM, Marcus, Jeffrey
jeffrey.mar...@nuance.com wrote:
 Orvalho:
  Thanks for pointing our RMySQL. The reason is that we have similar data 
 stored in both SQL server and MySQL databases and I want to reuse code as 
 much as possible.

  Jeff


 -Original Message-
 From: Orvalho Augusto [mailto:orvaq...@gmail.com]
 Sent: Wednesday, January 13, 2010 10:57 PM
 To: Marcus, Jeffrey
 Cc: r-help@r-project.org
 Subject: Re: [R] FW: Problems connecting with MySQL using odbcDriverConnect 
 (RODBC package) on Linux

 Thanks you solved and share with us.

 But, why don't you use the RMySQL, which connects to MySQL without the
 need of ODBC?

 Caveman


 On Wed, Jan 13, 2010 at 1:48 AM, Marcus, Jeffrey
 jeffrey.mar...@nuance.com wrote:
 I think I figured this out. I should not have put the Driver name in
 braces. Changing it from {MySQL} to MySQL seems to work.

 -Original Message-
 From: Marcus, Jeffrey
 Sent: Tuesday, January 12, 2010 6:09 PM
 To: 'r-help@r-project.org'
 Subject: Problems connecting with MySQL using odbcDriverConnect (RODBC
 package) on Linux

 I am sure I'm doing something wrong here but not sure what.

 Our system administrator recently installed UnixODBC and the MyODBC
 driver on a Linux box running Linux version 2.6 x86_64.

 I have an .odbc.ini file in my home directory with following lines:

 [mydb]
 Description = MySQL server on my-server
 Driver=/usr/lib64/libmyodbc3.so
 SERVER=my-server

 I can successfully do the following:

 library(RODBC)
 channel - odbcConnect(mydb)
 sqlQuery(channel, show databases)

 And in general, I have no problems using odbcConnect to connect to the
 mydb DSN.

 However, for various reasons I want to make a DSN-less connection
 using odbcDriverConnect. However, everything I've tried generated a
 data source not found message (see below for details)

  After reading through various documents, I tried doing following.

 (1) Put an odbcinst.ini file in my home directory with following lines
 [MySQL]
 Description     = ODBC for MySQL
 Driver=/usr/lib64/libmyodbc3.so
 Setup           = /usr/lib/libodbcmyS.so
 FileUsage       = 1

 (2) Install it with odbcinst -i -f. This seems to work as when I type
 odbcinst -j I get

 DRIVERS: /home/jmarcus/odbcinst.ini
 SYSTEM DATA SOURCES: /home/jmarcus/odbc.ini
 USER DATA SOURCES..: /home/jmarcus/.odbc.ini


 (2) Set the environment variable to point to this file:

 bash-3.2$  ODBCSYSINI=/home/jmarcus
 bash-3.2$ export ODBCSYSINI

 (3) Start R

 Note that R has inherited environment variable
 Sys.getenv(ODBCSYSINI)

     ODBCSYSINI
 /home/jmarcus

 (4) Try to connect to the MySQL server

   conn -
 odbcDriverConnect(connection=Driver={MySQL};Server=my-server;Database=m
 y_database;Uid=my_username;Pwd=my_password)

 This generates following:

 Warning messages:
 1: In odbcDriverConnect(connection =
 Driver={MySQL};Server=my-server;Database=my_database;Uid=my_username;Pw
 d=my_password) :
  [RODBC] ERROR: state IM002, code 0, message [unixODBC][Driver
 Manager]Data source name not found, and no default driver specified
 2: In odbcDriverConnect(connection =
 Driver={MySQL};Server=my-server;Database=my_database;Uid=my_username;Pw
 d=my_password) :
  ODBC connection failed


 Can anyone see what I'm doing wrong? Thanks.

  Jeff

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




 --
 OpenSource Software Consultant
 CENFOSS (www.cenfoss.co.mz)
 SP Tech (www.sptech.co.mz)
 email: orvaq...@cenfoss.co.mz
 cell: +258828810980




-- 
OpenSource Software Consultant
CENFOSS (www.cenfoss.co.mz)
SP Tech (www.sptech.co.mz)
email: orvaq...@cenfoss.co.mz
cell: +258828810980

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

2010-01-15 Thread Uwe Ligges

You can access the sources yourself.
How to find the right file is described in
Ligges, U. (2006): R Help Desk: Accessing the Sources. R News 6 (4), 
43-45. http://cran.r-project.org/doc/Rnews/Rnews_2006-4.pdf


Best wishes,
Uwe Ligges




On 15.01.2010 10:54, Federico Bonofiglio wrote:

hello R-Wizards! again i'm invoking your presence!!

since all the fuss about the paradoxes on a computer algorithm generating
caos or un-determinancy, i recently grew quite curious about the mechanism
underlying the procedure of NUMBER RADOMIZATION.

could anyone of you, masters, attach me the algorithm (or source code? is it
right?) behind the *sample()* function, so i can inspect in detail the
mechanism of this so gossiped radomization?

thank you, sincerely

federico bonofiglio,
student of statistics at
milano bicocca university,
italia

[[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 color a splom?

2010-01-15 Thread Uwe Ligges



On 14.01.2010 11:11, Marius Hofert wrote:

Dear R-Users,

I would like to color the data in a splom according to their position in the matrix, i.e. 
I would like to have all data shown in the upper left corner to be blue, all entries 
below that to be black, and the data to the right to be all red. I tried to color the 
splom with the following call...

splom(~iris[1:3],col=c(black,blue,red))

...however, the colors are mixed. I also constructed a matrix containing the 
required colors, but that also did not work. How do I color the splom according 
to the location in the matrix as mentioned above?


Do you mean color by the levels of Species?

 splom( ~ iris[1:3], col = c(black,blue,red)[iris[,4]])

Best wishes,
Uwe




Cheers,

Marius

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

2010-01-15 Thread Michael Friendly

Thanks, Henrique
I *do* need to preserve the type of each list element (num or chr).
Thus, a first step might be

 as.data.frame(testlist, stringsAsFactors=FALSE)
 shape cell.fill back.fill scale.max
1 0   red white   100
2 0  blue white   100
3 2 green white   100
 str(as.data.frame(testlist, stringsAsFactors=FALSE))
'data.frame':   3 obs. of  4 variables:
$ shape: num  0 0 2
$ cell.fill: chr  red blue green
$ back.fill: chr  white white white
$ scale.max: num  100 100 100

I think, with this mod, your #2 gives me what I want:

wanted.henrique - lapply(split(x - as.data.frame(testlist, 
stringsAsFactors=FALSE), 1:nrow(x)), as.list)

 str(wanted.henrique)
List of 3
$ 1:List of 4
 ..$ shape: num 0
 ..$ cell.fill: chr red
 ..$ back.fill: chr white
 ..$ scale.max: num 100
$ 2:List of 4
 ..$ shape: num 0
 ..$ cell.fill: chr blue
 ..$ back.fill: chr white
 ..$ scale.max: num 100
$ 3:List of 4
 ..$ shape: num 2
 ..$ cell.fill: chr green
 ..$ back.fill: chr white
 ..$ scale.max: num 100


Henrique Dallazuanna wrote:

Try this:

#'1) But apply converts all to 'character'
apply(as.data.frame(testlist), 1, as.list)

#2)
lapply(split(x - as.data.frame(testlist), 1:nrow(x)), as.list)

On Fri, Jan 15, 2010 at 11:09 AM, Michael Friendly frien...@yorku.ca wrote:
  

I have a list of vectors, all forced to be the same length:

testlist - list(
  shape=c(0, 0, 2),
 cell.fill=c(red,blue,green),
  back.fill=rep(white,3),
  scale.max=rep(100,3)
  )


str(testlist)
  

List of 4
$ shape: num [1:3] 0 0 2
$ cell.fill: chr [1:3] red blue green
$ back.fill: chr [1:3] white white white
$ scale.max: num [1:3] 100 100 100

I need to 'transpose' them into a list of lists with named values like so:


wanted - list(
  list(shape=0, cell.fill=red, back.fill=white, scale.max=100),
  list(shape=0, cell.fill=blue, back.fill=white, scale.max=100),
  list(shape=2, cell.fill=green, back.fill=white, scale.max=100)
  )


str(wanted)
  

List of 3
$ :List of 4
 ..$ shape: num 0
 ..$ cell.fill: chr red
 ..$ back.fill: chr white
 ..$ scale.max: num 3
$ :List of 4
 ..$ shape: num 0
 ..$ cell.fill: chr blue
 ..$ back.fill: chr white
 ..$ scale.max: num 3
$ :List of 4
 ..$ shape: num 2
 ..$ cell.fill: chr green
 ..$ back.fill: chr white
 ..$ scale.max: num 3

How can I do this in general?


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

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






  



--
Michael Friendly Email: friendly AT yorku DOT ca 
Professor, Psychology Dept.

York University  Voice: 416 736-5115 x66249 Fax: 416 736-5814
4700 Keele Streethttp://www.math.yorku.ca/SCS/friendly.html
Toronto, ONT  M3J 1P3 CANADA

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


[R] How to calculate the row wise means for grouped columns in matrix?

2010-01-15 Thread Joel Fürstenberg-Hägg

Hi all,

 

I want to calculate the row wise mean of groups of columns in a matrix M. All 
columns belonging to the same group have the same column name. My idea is to 
create a new vector V containing these column names, but after first removing 
the duplicates. Then I would calculate the means using for instance rowMean() 
and by comparing the column names of M with the vector V, getting the indices 
of the columns to use.

 

What do you think, is it a good idea or not? If yes, any suggestions how to do 
it? If no, is there any alternative solution that might work better?

 

 

 

All the best,

 

Joel
  
_
Lagra alla dina foton på Skydrive. Det är enkelt och säkert!
http://www.skydrive.live.com
[[alternative HTML version deleted]]

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


Re: [R] estimating rho of Poisson distributed data

2010-01-15 Thread David Winsemius


On Jan 15, 2010, at 5:59 AM, Titus von der Malsburg wrote:


Mean and variance of Poisson distributed data are specified by \rho.
How can I estimate \rho for a set of measurements in R?


rho - mean(x)


David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] estimating rho of Poisson distributed data

2010-01-15 Thread Titus von der Malsburg
On Fri, Jan 15, 2010 at 09:19:23AM -0500, David Winsemius wrote:

 On Jan 15, 2010, at 5:59 AM, Titus von der Malsburg wrote:

 Mean and variance of Poisson distributed data are specified by \rho.
 How can I estimate \rho for a set of measurements in R?

 rho - mean(x)

Yeah, thanks :-)  I was looking for a general way to fit a
distribution.  Should've made that clear.  I'm surprised that nobody
is complaining because I called lambda rho!

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] advice/opinion on - vs = in teaching R

2010-01-15 Thread John Kane
I've only been using R for about 2.5 years but and I'm not all that good  but I 
vote for - .

I think the deciding factor is in  RSiteSearch() and the various manuals.

Almost everything I see uses - .  Why introduce = when it is not used 
normally?  It will just confuse the students who are trying to use any of the 
documentation.  

Not to mention they might slammed for bad syntax on the R-help mailing list.  :)



--- On Thu, 1/14/10, Erin Hodgess erinm.hodg...@gmail.com wrote:

 From: Erin Hodgess erinm.hodg...@gmail.com
 Subject: [R] advice/opinion on - vs = in teaching R
 To: R help r-h...@stat.math.ethz.ch
 Received: Thursday, January 14, 2010, 10:45 PM
 Hi R People:
 
 I'm teaching a statistical computing class using R starting
 next week
 (yay!) and I have an opinion type question, please.
 
 I'm old school and use - in an assignment.
 
 However, I'm starting to see the = in the literature.
 
 Which should I use or does it matter, please?
 
 Thanks for your input!
 Sincerely,
 Erin
 
 
 -- 
 Erin Hodgess
 Associate Professor
 Department of Computer and Mathematical Sciences
 University of Houston - Downtown
 mailto: erinm.hodg...@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.
 


  __
The new Internet Explorer® 8 - Faster, safer, easier.  Optimized for Yahoo!  
Get it Now for Free! at http://downloads.yahoo.com/ca/internetexplorer/

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

2010-01-15 Thread klausch
Dear R-experts,

this is not a direct R-problem but I hope you can help me anyway.

I would like to minimize || PG-I || over P, where P is a p x p permutation 
matrix (obtained by permuting the rows and/or columns of the identity matrix), 
G is a given p x p matrix with full rank and I the identity matrix.  ||.|| is 
the frobenius norm.

Does anyone know an algorithm to solve such a problem? And if yes, is it 
implemented in R?

Currently I minimize it by going through all possible permutations - but this 
is not feasible for higher dimensional problems as I would like to consider too.

Any help is appreciated!

Thanks in advance,

Klaus

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3.5 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] What is the newline escape sequence when using the Hershey fontfamily?

2010-01-15 Thread Douglas Walcerz

Hello!

The question is simple: What is the escape sequence for a new line when 
using Hershey fonts?  I obviously tried '\n' but it didn't work (see the 
sample below).  I looked at 'demo(Hershey)' but all it only shows escape 
sequences for printable characters.


The sample I've been using to try to find the escape sequence is below.  
You can comment or un-comment the fontfamily line to turn Hershey on or off.


xx - c(1:10)
yy - c(11:20)
xyplot(yy~xx,
   main=list(This title should\nhave two lines
#, fontfamily=HersheySans
   )
)

Thanks,
Douglas

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Advantages of using SQLite for data import in comparison to csv files

2010-01-15 Thread Juliet Jacobson
Thanks for your answer.
I've thought of the possibility of an index when using a SQLite database, but 
as you mentioned, I don't really benefit from it in regard of rather small 
data sets. 
What I am considering as a problem when using csv files is the occurrence of 
data redundancy: When I wan't to print a table in a document, it is often not  
necessary to insert all columns of a table. You might choose to leave out 
certain parameters that are aren't of interest for the reader. I feared that 
the generation of a second table with less information would be unavoidable 
in this case before including it in LaTeX with Sweave. However, after having 
tried to get started with sqldf, this powerful addition to R's data analysis 
and manipulation abilities is probably sufficient for my purposes.

Best regards,
Juliet


 RSQLite is actually much more than a driver for data import. It
 basically allows any manipulation of SQLite databases, including
 reading, writing, or updating and munging data within the database.


 Regarding the original question of data import:

 I use csv and sqlite files interchangeably to store my data, and
 converting between one and the other is generally trivial (read one
 format into a data.frame and then write it into the other).

 For me, the key determinant is whether a given data set is so big that
 reading it into a data.frame with read.csv() every time I need it is a
 pain. I usually keep all my original data in csv files and write
 routines to write the contents of huge files into sqlite databases.

 sqldf is a great package as well, but it definitely does not obviate the
 need to actually be able to manipulate data base files. For one thing,
 you cannot index a csv file or a data.frame. If you have to repeatedly
 select subsets of your large data set, creating an index on the relevant
 column in the sqlite table is an absolute life saver.

 (However, with a 1000x20 data set, you will probably not have to worry
 about the speed of selecting from the table. Unless you need to use
 bigger data sets, the simplest way is probably to just use csv files,
 read the contents into a data.frame with read.csv, and then use sqldf on
 the data.frame if you need to do complicated subsetting)

 Best,
 Magnus

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

2010-01-15 Thread Walther, Alexander
Dear list,

i try to set up a GUI with gWidgets. For this project, RGtk2 is
required. By loading the package, i encounter the following error prompt:


---C Symbolname S_gtk_icon_factory_new not in DLL for package RGtk2---


Any suggestions how to fix this? And: is there a good resource for
gWidgets templates on the web?


Best regards

Alex

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Lattice: How to color the data points in splom() according to the panel they are plotted?

2010-01-15 Thread Marius Hofert
Dear ExpeRts,

I have the scatter plot matrix as given below. I would like the different 
sub-plots in the scatter plot matrix to be colored differently. How do I get 
all points shown in the upper-left plot (on position (1,1) in the scatter plot 
matrix) to be plotted in blue, and the points shown in the plot to the right 
(on position (1,2) in the scatter plot matrix) to be plotted in red? More 
generally, how can I provide a matrix of colors to be used by splom() such that 
all data points in the corresponding sub-plot of the scatter plot matrix are 
shown in the specified color?

Cheers,

Marius

Here is the code:

library(lattice)

entrymat=matrix(0,nrow=3,ncol=3)
entrymat[1,2]=black
entrymat[1,3]=blue
entrymat[2,3]=red
entrymat=t(entrymat)

splom(~iris[,1:3],superpanel=function(z,...){

mymat.df=data.frame(rows=as.vector(row(entrymat)),cols=as.vector(col(entrymat)),entries=as.vector(entrymat))
mymat.df=subset(mymat.df,colsrows)
with(mymat.df,{
panel.text(x=rows,y=cols,labels=entries)
})

panel.pairs(z,upper.panel=panel.splom,lower.panel=function(...){},...)
},varnames=c(1,2,3)
)

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

2010-01-15 Thread Larry Hotchkiss
One way to add the text is to use a list with named elements for the row and 
column names:

   (M - matrix(1:9, ncol=3, byrow=TRUE,
+   dimnames=list( =LETTERS[1:3],
+ THIS IS AN EXAMPLE\nOF a 3x3 MATRIX=LETTERS[1:3])) )
   THIS IS AN EXAMPLE
OF a 3x3 MATRIX
A B C
  A 1 2 3
  B 4 5 6
  C 7 8 9

Larry Hotchkiss


- Original Post -
Message: 7
Date: Thu, 14 Jan 2010 11:04:27 +0100
From: carfer...@alum.us.es
To: r-help@r-project.org
Subject: [R] To add text in a matrix
Message-ID: f61eaf1f1d8d7.4b4ef...@us.es
Content-Type: text/plain; charset=us-ascii

Dear colleagues,

I would need to add text (some rows of information) in a matrix. For example, 
given this matrix


1 2 3
4 5 6
7 8 9

I would need to add this info:

THIS IS AN EXAMPLE
OF a 3x3 MATRIX
1 2 3
4 5 6
7 8 9


I have been looking for a function that works similar to fopen in matlab, but 
unfortunately I have not found It in R.

Thank you in advance for your help!

Carlos Fernandez

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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 calculate the row wise means for grouped columns in matrix?

2010-01-15 Thread Benilton Carvalho
adapted from the help files of rowsum

x - matrix(runif(100), ncol=5)
group - sample(1:8, 20, TRUE)
xsum - rowsum(x, group)
sweep(xsum, 1, table(group), /)

or

aggregate(x, list(group), mean)[-1]

b

2010/1/15 Joel Fürstenberg-Hägg joel_furstenberg_h...@hotmail.com:

 Hi all,



 I want to calculate the row wise mean of groups of columns in a matrix M. All 
 columns belonging to the same group have the same column name. My idea is to 
 create a new vector V containing these column names, but after first removing 
 the duplicates. Then I would calculate the means using for instance rowMean() 
 and by comparing the column names of M with the vector V, getting the indices 
 of the columns to use.



 What do you think, is it a good idea or not? If yes, any suggestions how to 
 do it? If no, is there any alternative solution that might work better?







 All the best,



 Joel

 _
 Lagra alla dina foton på Skydrive. Det är enkelt och säkert!
 http://www.skydrive.live.com
[[alternative HTML version deleted]]


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



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


Re: [R] estimating rho of Poisson distributed data

2010-01-15 Thread Peter Ehlers



Titus von der Malsburg wrote:

On Fri, Jan 15, 2010 at 09:19:23AM -0500, David Winsemius wrote:

On Jan 15, 2010, at 5:59 AM, Titus von der Malsburg wrote:


Mean and variance of Poisson distributed data are specified by \rho.
How can I estimate \rho for a set of measurements in R?

rho - mean(x)


Yeah, thanks :-)  I was looking for a general way to fit a
distribution.  Should've made that clear.  I'm surprised that nobody
is complaining because I called lambda rho!


Why would anyone complain? You're free to call it 'applesauce'
if that suits you.

What do you mean by 'general way to fit a distribution'?
Maximum likelihood might be one way.

 -Peter Ehlers


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




--
Peter Ehlers
University of Calgary
403.202.3921

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

2010-01-15 Thread Bryan S.
Hi all,

This question is more stats related than R related, but as I will be doing
these analyses in R, there may be some programming questions to follow.  I
figured it best to start here.

To keep things relatively simple, assume that I recently fielded a survey
over three weeks.  I have three dichotomous variables that indicate what
week a respondent responded in. I would like test to see if the percent
responding in each week is significantly different.  (For example, 24%
responded in week 1 and 28% in week 2.  Were there significantly more
respondents in week 2?)

Here is the data layout:

ID  Week1  Week2  Week3
1 10   0
2 01   0
3 10   0
4 01   0
5 01   0
6 00   1
7 00   1


It seems like this could be done as difference of percentages test, but I am
not sure how to account for the third option.

Any help is appreciated.

Bryan

[[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] estimating rho of Poisson distributed data

2010-01-15 Thread Titus von der Malsburg
On Fri, Jan 15, 2010 at 08:33:52AM -0700, Peter Ehlers wrote:
 Why would anyone complain? You're free to call it 'applesauce'
 if that suits you.

Good idea, I will do this from now on!  ;-)

 What do you mean by 'general way to fit a distribution'?
 Maximum likelihood might be one way.

Somebody else pointed me to fitdistr from MASS which does the job.

Thanks for the reply!

  Titus

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] estimating rho of Poisson distributed data

2010-01-15 Thread David Winsemius


On Jan 15, 2010, at 9:46 AM, Titus von der Malsburg wrote:


On Fri, Jan 15, 2010 at 09:19:23AM -0500, David Winsemius wrote:


On Jan 15, 2010, at 5:59 AM, Titus von der Malsburg wrote:


Mean and variance of Poisson distributed data are specified by \rho.
How can I estimate \rho for a set of measurements in R?


rho - mean(x)


Yeah, thanks :-)


Hey, ask a simple question,  get a simple answer.


I was looking for a general way to fit a
distribution.  Should've made that clear.  I'm surprised that nobody
is complaining because I called lambda rho!


There is a fitdistr function in MASS which would be extreme overkill  
for the problem posed and:


http://cran.r-project.org/doc/contrib/Ricci-distributions-en.pdf

What other trivial searching can I do for you?

--

David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] advice/opinion on quot; lt; -quot; vs quot; =quot; in teaching R

2010-01-15 Thread Ben Bolker
John Kane jrkrideau at yahoo.ca writes:

 
 I've only been using R for about 2.5 years but and I'm not all that good  but
I vote for - .
 
 I think the deciding factor is in  RSiteSearch() and the various manuals.
 
 Almost everything I see uses - .  Why introduce = when it is not used
normally?  It will just confuse the
 students who are trying to use any of the documentation.  
 
 Not to mention they might slammed for bad syntax 
 on the R-help mailing list.  :)
 

  Those are all good reasons.
  I have said something similar before
(see http://www.mail-archive.com/r-help@r-project.org/msg16904.html),
but I tend to use = because it seems to be more intuitive for 
students, despite being logically confused at a deeper level, 
and I want to spare them any additional cognitive load when they 
are first getting introduced to R.
   I'm not particularly convinced by the - is more general
and there are some contexts where = doesn't work, because I'm
not trying to be absolutely rigorous, nor teach all the possible
ins and outs of R syntax. I would be very surprised if any of
the examples given actually came up in the course of a first-semester
statistics/modeling R course. I just want to do what works best for
the students -- the problem is deciding on the balance between
short term benefit (- is one more odd thing to get used to)
and long term benefit (they will see - in other contexts, so
they might as well get used to it eventually).

  Ben Bolker

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


Re: [R] advice/opinion on - vs = in teaching R

2010-01-15 Thread Thomas Lumley

On Fri, 15 Jan 2010, Barry Rowlingson wrote:


On Fri, Jan 15, 2010 at 6:57 AM, Ted Harding
ted.hard...@manchester.ac.ukwrote:



There is at least one context where the distinction must be
preserved. Example:

 pnorm(1.5)
 # [1] 0.9331928
 pnorm(x=1.5)
 # Error in pnorm(x = 1.5) : unused argument(s) (x = 1.5)
 pnorm(x-1.5)
 # [1] 0.9331928
 x
 # [1] 1.5

Ted.



I would regard modifying a variable within the parameters of a function
call as pretty tasteless. What does:


foo(x-2,x)
or
foo(x,x-3)

do that couldn't be done clearer with two lines of code?



It allows the lazy evaluation mechanism to determine whether the  assignment 
happens. That would be very hard to do in two lines of code.

-thomas

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

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


Re: [R] advice/opinion on - vs = in teaching R

2010-01-15 Thread Thomas Lumley

On Thu, 14 Jan 2010, Erin Hodgess wrote:


Hi R People:

I'm teaching a statistical computing class using R starting next week
(yay!) and I have an opinion type question, please.

I'm old school and use - in an assignment.

However, I'm starting to see the = in the literature.

Which should I use or does it matter, please?


I would say to use = if you are teaching people familiar with C or Java, and to 
use - otherwise.

  -thomas

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

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


Re: [R] estimating rho of Poisson distributed data

2010-01-15 Thread John Sorkin
If you use 
fit1-glm(y~x,offset=offset,family=poisson(link=log))
you will get values for the Null deviance and residual deviance along with 
degrees of freedom for these parameters. One of these deviances divided by its 
degrees of freedom might be what you are looking for. but I am not sure. 
Perhaps other list members will either confirm my suspicion, or correct my 
misconception.
John







John David Sorkin M.D., Ph.D.
Chief, Biostatistics and Informatics
University of Maryland School of Medicine Division of Gerontology
Baltimore VA Medical Center
10 North Greene Street
GRECC (BT/18/GR)
Baltimore, MD 21201-1524
(Phone) 410-605-7119
(Fax) 410-605-7913 (Please call phone number above prior to faxing) Peter 
Ehlers ehl...@ucalgary.ca 1/15/2010 10:33 AM 


Titus von der Malsburg wrote:
 On Fri, Jan 15, 2010 at 09:19:23AM -0500, David Winsemius wrote:
 On Jan 15, 2010, at 5:59 AM, Titus von der Malsburg wrote:

 Mean and variance of Poisson distributed data are specified by \rho.
 How can I estimate \rho for a set of measurements in R?
 rho - mean(x)
 
 Yeah, thanks :-)  I was looking for a general way to fit a
 distribution.  Should've made that clear.  I'm surprised that nobody
 is complaining because I called lambda rho!
 
Why would anyone complain? You're free to call it 'applesauce'
if that suits you.

What do you mean by 'general way to fit a distribution'?
Maximum likelihood might be one way.

  -Peter Ehlers

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

-- 
Peter Ehlers
University of Calgary
403.202.3921

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

Confidentiality Statement:
This email message, including any attachments, is for th...{{dropped:6}}

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

2010-01-15 Thread j verzani
Walther, Alexander awalthermail at googlemail.com writes:

 
 Dear list,
 
 i try to set up a GUI with gWidgets. For this project, RGtk2 is
 required. By loading the package, i encounter the following error prompt:
 
 ---C Symbolname S_gtk_icon_factory_new not in DLL for package RGtk2-
--
 

This sounds like an RGtk2 issue and for that it depends on your system. Can you 
load RGtk2 by itself and issue some command, say gtkWindow()? If not, that is 
where to look.

 Any suggestions how to fix this? And: is there a good resource for
 gWidgets templates on the web?
 

There is a vignette with the package, and some examples at 
www.math.csi.cuny.edu/pmg/gWidgets/Examples. As well, there are some 
examples at www.math.csi.cuny.edu/gWidgetsWWW that should work here as 
well. Those might get you started.

--John


 Best regards
 
 Alex
 


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

2010-01-15 Thread Joe Conway
On 01/15/2010 01:49 AM, Bart Joosen wrote:
 
 One way could be to first select only the unique ID's, sample this and then
 select only the relevant records:
 
 strQuery = SELECT ID from tblFoo;
 IDs - sqlQuery(channel, strQuery)
 sample.IDs - sample(IDs,10)
 strQuery = paste(SELECT ID from tblFoo WHRE ID IN(, sample.IDs, );)
 IDs - sqlQuery(channel, strQuery)

Better is to use the built-in random() function in Postgres:

#select count(*) from visits;
  count
-
 4846604
(1 row)

# select count(*) from visits where random()  0.005;
 count
---
 24391
(1 row)

HTH,

Joe



signature.asc
Description: OpenPGP digital signature
__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] panel.bpplot

2010-01-15 Thread netrunner

Hi everybody,

I am a newbie in R. I would like to use the panel.bpplot function on my data
set but I have some problems. Can this function work on matrix? My data set
have some NaN and when I run panel.bpplot function it returns error due to
the presence of NaN. How Can I solve this?

Thank you so much for your help

netrunner
-- 
View this message in context: 
http://n4.nabble.com/panel-bpplot-tp1015050p1015050.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] optimization problem

2010-01-15 Thread Erwin Kalvelagen

 klausch at gmx.de writes:

 
 Dear R-experts,
 
 this is not a direct R-problem but I hope you can help me anyway.
 
 I would like to minimize || PG-I || over P, where P is a p x p permutation 
matrix (obtained by permuting the rows
 and/or columns of the identity matrix), G is a given p x p matrix with full 
rank and I the identity matrix. 
 ||.|| is the frobenius norm.
 
 Does anyone know an algorithm to solve such a problem? And if yes, is it 
implemented in R?
 
 Currently I minimize it by going through all possible permutations - but this 
is not feasible for higher
 dimensional problems as I would like to consider too.
 
 Any help is appreciated!
 
 Thanks in advance,
 
 Klaus
 




This could be modeled as a MIQP problem:

min sum((i,j),sqr(V(i,j)))
v(i,j) = sum(k, P(i,k)*G(k,j)) - Id(i,j);
sum(i, P(i,j)) = 1
sum(j, P(i,j)) = 1
P(i,j) in {0,1}

If you have access to Cplex then http://cran.r-
project.org/web/packages/Rcplex/Rcplex.pdf can help.

If you can use a different norm it may be possible to use linear MIP technology 
allowing a wider range of solvers.

This is combinatorial, so for p  20 say it may become slow (this also depends 
on the data).

Erwin


Erwin Kalvelagen
Amsterdam Optimization Modeling Group
er...@amsterdamoptimization.com
http://amsterdamoptimization.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] Can an object reference itself?

2010-01-15 Thread Janko Thyson
Dear List,

I am not really familiar with any other language than R, but I’ve heard that
in other languages there is something called “self referencing”.

Here’s what I’m trying to get an answer for:
Suppose there is a function that takes as its input a value of a slot of an
S4 object. The function itself is stored in another slot of the SAME S4
object. Is it then possible to have the function automatically “recognize”
the name of the object in which slot it is placed via some sort of “self
referencing” of the S4 object (to avoid having to explicitly state the
required function argument for different S4 object instances with different
names)?

I hope the following code snippets will give you an idea what I’m trying to
do:

obj.for.slot - data.frame(a=1); obj.for.slot - data.frame(a=100)
save(obj.for.slot, file=C:/obj.1.for.slot.Rdata); save(obj.for.slot,
file=C:/obj.2.for.slot.Rdata)

slotfun - function(obj.name)
{ 
file.fqn.char - paste(file.fqn - , obj.name, @file.fqn,
sep=)
eval(parse(text=file.fqn.char))
load(file=file.fqn)
return(obj.for.slot)
}

setClass(
Class=Testclass,
representation=representation(
file.fqn=character,
data=function
),
prototype=prototype(
file.fqn=blabla,
data=slotfun
)
)

test- new(Testclass)
test.mod- new(Testclass)


t...@file.fqn   - C:/obj.1.for.slot.Rdata
test@file.fqn   - C:/obj.2.for.slot.Rdata

t...@data(obj.name=test)
test@data(obj.name=test.mod)

I'm trying to have slotfun() be stated in a way that does not require an
explicit stating of argument obj.name):
t...@data()
test@data()

Any hints in the right directions greatly appreciated!

Regards,
Janko Thyson

janko.thy...@kuei.de

Catholic University of Eichstätt-Ingolstadt
Ingolstadt School of Management
Statistics and Quantitative Methods
Auf der Schanz 49
D-85049 Ingolstadt

www.wfi.edu/lsqm

Fon:  +49 841 937-1923
Fax:  +49 841 937-1965

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

2010-01-15 Thread Frank E Harrell Jr

netrunner wrote:

Hi everybody,

I am a newbie in R. I would like to use the panel.bpplot function on my data
set but I have some problems. Can this function work on matrix? My data set
have some NaN and when I run panel.bpplot function it returns error due to
the presence of NaN. How Can I solve this?

Thank you so much for your help

netrunner


Read documentation for lattice graphics.  Get your problem solved with 
bwplot() without panel=panel.bpplot then add the panel=.


Frank

--
Frank E Harrell Jr   Professor and ChairmanSchool of Medicine
 Department of Biostatistics   Vanderbilt University

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


Re: [R] panel.bpplot

2010-01-15 Thread Dieter Menne



netrunner wrote:
 
 I am a newbie in R. I would like to use the panel.bpplot function on my
 data set but I have some problems. Can this function work on matrix? My
 data set have some NaN and when I run panel.bpplot function it returns
 error due to the presence of NaN. How Can I solve this?
 
 

You should never use panel.bpplot directly, but rather in a bwplot()
function. See the examples coming with the documentation in package Hmisc.
Used correctly, it has no problem with NA. In general, one would use it with
a data.frame, because grouping is often a factor.

If this does not solve your problem, please repost with a modification of
the sample below that shows the problem.

Dieter


library(Hmisc)
set.seed(13)
data = data.frame(x =rnorm(1000), g - sample(1:6, 1000, replace=TRUE))
bwplot(g ~ x, panel=panel.bpplot, data=data)
# Add NA
data$x[1:3] = NA
data$x[data$g==6]  = NA
bwplot(g ~ x, panel=panel.bpplot, data=data)

-- 
View this message in context: 
http://n4.nabble.com/panel-bpplot-tp1015050p1015105.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] Can an object reference itself?

2010-01-15 Thread hadley wickham
On Fri, Jan 15, 2010 at 5:30 PM, Janko Thyson
janko.thy...@ku-eichstaett.de wrote:
 Dear List,

 I am not really familiar with any other language than R, but I’ve heard that
 in other languages there is something called “self referencing”.

 Here’s what I’m trying to get an answer for:
 Suppose there is a function that takes as its input a value of a slot of an
 S4 object. The function itself is stored in another slot of the SAME S4
 object. Is it then possible to have the function automatically “recognize”
 the name of the object in which slot it is placed via some sort of “self
 referencing” of the S4 object (to avoid having to explicitly state the
 required function argument for different S4 object instances with different
 names)?

 I hope the following code snippets will give you an idea what I’m trying to
 do:

 obj.for.slot - data.frame(a=1); obj.for.slot - data.frame(a=100)
 save(obj.for.slot, file=C:/obj.1.for.slot.Rdata); save(obj.for.slot,
 file=C:/obj.2.for.slot.Rdata)

 slotfun - function(obj.name)
 {
        file.fqn.char - paste(file.fqn - , obj.name, @file.fqn,
 sep=)
        eval(parse(text=file.fqn.char))
        load(file=file.fqn)
        return(obj.for.slot)
 }

 setClass(
        Class=Testclass,
        representation=representation(
                file.fqn=character,
                data=function
        ),
        prototype=prototype(
                file.fqn=blabla,
                data=slotfun
        )
 )

 test            - new(Testclass)
 test.mod        - new(Testclass)


 t...@file.fqn           - C:/obj.1.for.slot.Rdata
 test@file.fqn       - C:/obj.2.for.slot.Rdata

 t...@data(obj.name=test)
 test@data(obj.name=test.mod)

An object does not have a unique name.  What would happen in the
following situations?

t3 - test.mod
tests - list(
  test,
  test.mod
)

Hadley

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

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


Re: [R] Advantages of using SQLite for data import in comparison to csv files

2010-01-15 Thread Matthew Dowle
Just to comment on this bit :

 For one thing, you cannot index a csv file or a data.frame. If you have to 
 repeatedly select subsets of your large data set, creating an index on the 
 relevant column in the sqlite table is an absolute life saver.

This is one reason the data.table package was created.  It is very similar 
to a data.frame, with the addition of things like keys.  If you consider an 
index in sqlite a life saver then data.table might be up your street.

Its really simple to do this in R.

For example, lets say you have a 10,000,000 row table of 2 columns : 
id(integer), v(double).  So this is a tiny example at just 115MB i.e. 
(4+8)*1e7/1024^2.   This is many times smaller than most desktop users have 
RAM available to R on their 32bit machines,  so you can run this example 
yourself.

W'll start off with data.frame and then show how data.table compares.

 n=1e7
 DF = data.frame(id=sample(LETTERS,n,replace=TRUE),v=rnorm(n))
 head(DF)
  id   v
1  P -0.57695495
2  A -0.33388390
3  P  0.05277701
4  K  0.49610573
5  F  0.31031501
6  C  1.26861215
 dim(DF)
[1] 10002
 system.time(DF[DF$id==G,])   # table scan  i.e. the == in R tests all 
 10m items, there is no index used as you said
   user  system elapsed
   1.230.171.41
 system.time(DF[DF$id==G,])   #  good idea to repeat all timings in case 
 the first one was slow due to a garbage collect
   user  system elapsed
   1.360.171.53

 DT = data.table(DF)# convert the data.frame to a data.table
 object.size(DF)
120001608 bytes
 object.size(DT)
120001640 bytes# so a DT is the same structure as a 
data.frame taking the same space.  data.frame is efficiently stored.  Can't 
get lower than the 115MB calculation for this dataset.   data.table doesn't 
do any magic with regard to storage

# Now comes the fun :

 setkey(DT,id)#  sort the data.table by id and marks it as sorted 
 by id. The key is now id.  This is analogous to building the index that 
 you do in sqllite.  You don't have to assign the result of setkey() 
 anywhere, unlike most R functions. Its a special function which operates 
 on DT and changes it directly.
 tables()# view all our tables in memory, theres just 
 one in this example.  It assumes you view the result in a font such as 
 courier.
 NAME   NROW  MB COLS KEY
[1,] DT   10,000,000 115 id,v id
Total: 115MB
  # R is looking a bit like a database now.  Usually you have lots of 
 tables returned by tables(),  just like you would with sqlTables() in 
 RODBC.

Its not difficult to use the key,  its very like using rownames :

 system.time(DT[G,mult=all])
   user  system elapsed
   0.090.000.09
 system.time(DT[G,mult=all])  # repeat the timing test.  confirmed 
 that 1.5s reduces to 0.1s
   user  system elapsed
0.1 0.0 0.1
 identical(   DF[DF$id==G,]$v, DT[G,mult=all]$v   )
[1] TRUE


The mult=all is needed because otherwise you'd just get the first row of 
the G group  (the default for mult is first when multiple rows match the 
key value)

Its very important to realise that in a data.table query you have the option 
to do table scans too e.g. :

 system.time(DT[id==G]) # its the == operator that results in a table 
 scan,  its not the class of the table per se
   user  system elapsed
   1.390.121.52


So its up to the user of data.table. The user has the option to use 
data.table badly (by not using the key),  just like you can use SQL badly 
(by not using an index)

Ok, who cares. 1 second saved. Why all the effort ?  Two reasons.  Firstly, 
try doubling the rows in DF and the time doubles to 3 seconds, double the 
rows in the DT though and that time stays constant at 0.1 seconds. Keep on 
doubling and the savings get bigger and bigger. Secondly, if you're 
repeating that 'query' inside a loop then the time saving adds up.  There 
are other advantages of data.table but it seemed appropriate just to mention 
the keys this time.

HTH


Magnus Torfason zulutime@gmail.com wrote in message 
news:4b4f9c70.2050...@gmail.com...
 RSQLite is actually much more than a driver for data import. It 
 basically allows any manipulation of SQLite databases, including reading, 
 writing, or updating and munging data within the database.


 Regarding the original question of data import:

 I use csv and sqlite files interchangeably to store my data, and 
 converting between one and the other is generally trivial (read one format 
 into a data.frame and then write it into the other).

 For me, the key determinant is whether a given data set is so big that 
 reading it into a data.frame with read.csv() every time I need it is a 
 pain. I usually keep all my original data in csv files and write routines 
 to write the contents of huge files into sqlite databases.

 sqldf is a great package as well, but it definitely does not obviate the 
 need to actually be able to manipulate data base files. For one thing, you 
 

[R] cbind or ?

2010-01-15 Thread L.A.


Hey Guys,
  It sure seems I get stuck on things that should be easy.
Heres my question:

PARCELS-by(ResImp[ , ACCOUNTNO], ResImp[Property], length)

 PARCELS
Property: UNSOLD
[1] 9053
---
 
Property: SOLD
[1] 578
---
 
Property: SubSale
[1] 52


QuanImpUnsold-with(ResImp, by(Appraisal, Property,
FUN=function(x)quantile(x, 
probs = c(1,25,50,75,90)/100)))

 QuanImpUnsold
Property: UNSOLD
  1%  25%  50%  75%  90% 
 18106.4  92817.0 131794.0 185742.0 262365.0 
---
 
Property: SOLD
   1%   25%   50%   75%   90% 
 35335.65 105034.25 138967.00 181971.25 254946.00 
---
 
Property: SubSale
   1%   25%   50%   75%   90% 
 37255.72 117055.50 149314.00 196207.00 259288.60 


tb-cbind(PARCELS, QuanImpUnsold)

tb
PARCELS QuanImpUnsold
UNSOLD  9053Numeric,5
SOLD578 Numeric,5
SubSale 52  Numeric,5

This is what I want

 tb
Property: UNSOLD
   Parcels   1%  25%  50%  75%  90% 
905318106.4  92817.0 131794.0 185742.0 262365.0 
---
 
Property: SOLD
   Parcels   1%   25%   50%   75%   90% 
 57835335.65 105034.25 138967.00 181971.25 254946.00 
---
 
Property: SubSale
  Parcels   1%   25%   50%   75%   90% 
  52   37255.72 117055.50 149314.00 196207.00 259288.60 

Any suggestions?
Thanks,
L.A.

Don't know if this helps:
 str(PARCELS)
 'by' int [1:3(1d)] 9053 578 52
 - attr(*, dimnames)=List of 1
  ..$ Property: chr [1:3] UNSOLD SOLD SubSale
 - attr(*, call)= language by.default(data = ResImp[, ACCOUNTNO],
INDICES = ResImp[Property],  FUN = length)

 str(QuanImpUnsold)
List of 3
 $ UNSOLD : Named num [1:5] 18106 92817 131794 185742 262365
  ..- attr(*, names)= chr [1:5] 1% 25% 50% 75% ...
 $ SOLD   : Named num [1:5] 35336 105034 138967 181971 254946
  ..- attr(*, names)= chr [1:5] 1% 25% 50% 75% ...
 $ SubSale: Named num [1:5] 37256 117056 149314 196207 259289
  ..- attr(*, names)= chr [1:5] 1% 25% 50% 75% ...
 - attr(*, dim)= int 3
 - attr(*, dimnames)=List of 1
  ..$ Property: chr [1:3] UNSOLD SOLD SubSale
 - attr(*, call)= language by.default(data = Appraisal, INDICES =
Property, FUN = function(x) quantile(x,  probs = c(1, 25, 50, 75,
90)/100))
 - attr(*, class)= chr by

-- 
View this message in context: 
http://n4.nabble.com/cbind-or-tp1015187p1015187.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] cbind or ?

2010-01-15 Thread Henrique Dallazuanna
Try this:

`class-`(lapply(1:length(QuanImpUnsold),
function(idx)c(QuanImpUnsold[[idx]], PARCELS[[idx]])), by)

On Fri, Jan 15, 2010 at 5:06 PM, L.A. ro...@millect.com wrote:


 Hey Guys,
  It sure seems I get stuck on things that should be easy.
 Heres my question:

 PARCELS-by(ResImp[ , ACCOUNTNO], ResImp[Property], length)

 PARCELS
 Property: UNSOLD
 [1] 9053
 ---
 Property: SOLD
 [1] 578
 ---
 Property: SubSale
 [1] 52


 QuanImpUnsold-with(ResImp, by(Appraisal, Property,
 FUN=function(x)quantile(x,
 probs = c(1,25,50,75,90)/100)))

 QuanImpUnsold
 Property: UNSOLD
      1%      25%      50%      75%      90%
  18106.4  92817.0 131794.0 185742.0 262365.0
 ---
 Property: SOLD
       1%       25%       50%       75%       90%
  35335.65 105034.25 138967.00 181971.25 254946.00
 ---
 Property: SubSale
       1%       25%       50%       75%       90%
  37255.72 117055.50 149314.00 196207.00 259288.60


 tb-cbind(PARCELS, QuanImpUnsold)

 tb
        PARCELS QuanImpUnsold
 UNSOLD  9053    Numeric,5
 SOLD    578     Numeric,5
 SubSale 52      Numeric,5

 This is what I want

 tb
 Property: UNSOLD
   Parcels   1%      25%      50%      75%      90%
    9053    18106.4  92817.0 131794.0 185742.0 262365.0
 ---
 Property: SOLD
   Parcels   1%       25%       50%       75%       90%
     578    35335.65 105034.25 138967.00 181971.25 254946.00
 ---
 Property: SubSale
  Parcels   1%       25%       50%       75%       90%
      52   37255.72 117055.50 149314.00 196207.00 259288.60

 Any suggestions?
 Thanks,
 L.A.

 Don't know if this helps:
 str(PARCELS)
  'by' int [1:3(1d)] 9053 578 52
  - attr(*, dimnames)=List of 1
  ..$ Property: chr [1:3] UNSOLD SOLD SubSale
  - attr(*, call)= language by.default(data = ResImp[, ACCOUNTNO],
 INDICES = ResImp[Property],      FUN = length)

 str(QuanImpUnsold)
 List of 3
  $ UNSOLD : Named num [1:5] 18106 92817 131794 185742 262365
  ..- attr(*, names)= chr [1:5] 1% 25% 50% 75% ...
  $ SOLD   : Named num [1:5] 35336 105034 138967 181971 254946
  ..- attr(*, names)= chr [1:5] 1% 25% 50% 75% ...
  $ SubSale: Named num [1:5] 37256 117056 149314 196207 259289
  ..- attr(*, names)= chr [1:5] 1% 25% 50% 75% ...
  - attr(*, dim)= int 3
  - attr(*, dimnames)=List of 1
  ..$ Property: chr [1:3] UNSOLD SOLD SubSale
  - attr(*, call)= language by.default(data = Appraisal, INDICES =
 Property, FUN = function(x) quantile(x,      probs = c(1, 25, 50, 75,
 90)/100))
  - attr(*, class)= chr by

 --
 View this message in context: 
 http://n4.nabble.com/cbind-or-tp1015187p1015187.html
 Sent from the R help mailing list archive at Nabble.com.

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




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

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


[R] bootstrapping

2010-01-15 Thread aaron.foley

Hi All,

 

I'm new to R so please bear with me.  I have a dataset with 337 turn angles 
ranging from -180 to 180 degrees.  I need to bootstrap (sample with 
replacement) 1,000 times to create expected average turn angle with 95% CIs.  
The code is pretty straightforward (-boot(data =, statistic = ,R =)) but I am 
unsure how to input my observed mean (6 degrees) and standard deviation (66 
degrees) into the statistic component.   I realize there is a 'function' code 
but I can't seem to carry the results over to the 'boot' code.

 

Thanks,

Aaron M. Foley
PhD Candidate
Caesar Kleberg Wildlife Research Institute
Texas AM University - Kingsville
Cousins Hall, Room 201
Kingsville, TX 78363



  
[[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] 'nlme' library - lme function results

2010-01-15 Thread Michal Figurski

Dear R-helpers

I am running a simple mixed effects model using lme(). The call looks 
like this:

fit - lme(Analyte~Sample, data=Data, random=~1 | Run)

I am particularly interested in the estimated random effects. When I 
print the 'fit' object, it looks something like example below:


(...)
Random effects:
 Formula: ~1 | Run
(Intercept) Residual
StdDev:3.483794 3.637523
(...)

While I have no problem obtaining the 'Residual' value by calling 
fit$sigma, I have no idea how to obtain the '(Intercept)' value from the 
'fit' object. Anyone can help with that?


Best regards,

--
Michal J. Figurski, PhD
HUP, Pathology  Laboratory Medicine
Biomarker Research Laboratory
3400 Spruce St. 7 Maloney
Philadelphia, PA 19104
tel. (215) 662-3413

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Possible to write text inside a bar of a barplot?

2010-01-15 Thread Rex C. Eastbourne
How can I write text inside a bar of a barplot? I tried using text(), but I
am only able to specify the numeric y-coordinate. The different columns of
my barplot correspond to factors and not numbers, so I don't know how to
access the horizontal positions of the bars. I tried fiddling with different
values of the adj argument, but this appears unreliable.

Background: I have created a barplot visualization where the bars represent
the size of different items (e.g. US state populations), and the sub-bars
represent the size of the different sub-components of each item (e.g.
counties). Picture: http://drop.io/hjcodjj/asset/capture-png

I would like to put in a label inside each sub-bar (e.g. indicating the name
of the county represented by that sub-bar).

Rex

p.s.: In case anyone finds this visualization useful I'll share my code
afterward, but just need to get the labeling working properly first.

[[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] R package dependencies

2010-01-15 Thread Seth Falcon

On 1/13/10 11:21 AM, James W. MacDonald wrote:

Hi Colin,

The pkgDepTools package from Bioconductor will help with question
#1:

http://bioconductor.org/packages/2.5/bioc/html/pkgDepTools.html

I am not positive on this, but I believe this package is also used
to determine the reverse dependencies that would be listed on that
page if there were any for this package. An example with reverse
dependencies is e.g., the IRanges package:

http://bioconductor.org/packages/2.5/bioc/html/IRanges.html

The maintainer (Seth Falcon) would know for sure if the package will
do reverse dependencies as well.


There is an example in the vignette for pkgDepTools that shows how to
get reverse dependencies:


The edge directions of the dependency graph can be reversed and the
resulting graph used to determine the set of packages that make use
of (even indirectly) a given package. For example, one might like to
know which packages make use of the methods package. Here is one way
to do that: example follows in the vignette


+ seth

--
Seth Falcon | @sfalcon | http://userprimary.net/user

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


[R] (no subject)

2010-01-15 Thread saleem mukhtar
Hello, 

I am running R on cygwin for windows. 

File R1234 contains 

data - read.table(data) 
q() 

On the command line I type 

R --no-save -q R_PROFILE=R1234 

returns 

Error: could not find function read.table 

THanks.

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] advice/opinion on quot; lt; -quot; vs quot; =quot; in teaching R

2010-01-15 Thread Douglas Bates
On Fri, Jan 15, 2010 at 10:00 AM, Ben Bolker bol...@ufl.edu wrote:
 John Kane jrkrideau at yahoo.ca writes:


 I've only been using R for about 2.5 years but and I'm not all that good  but
 I vote for - .

 I think the deciding factor is in  RSiteSearch() and the various manuals.

 Almost everything I see uses - .  Why introduce = when it is not used
 normally?  It will just confuse the
 students who are trying to use any of the documentation.

 Not to mention they might slammed for bad syntax
 on the R-help mailing list.  :)


  Those are all good reasons.
  I have said something similar before
 (see http://www.mail-archive.com/r-help@r-project.org/msg16904.html),
 but I tend to use = because it seems to be more intuitive for
 students, despite being logically confused at a deeper level,
 and I want to spare them any additional cognitive load when they
 are first getting introduced to R.
   I'm not particularly convinced by the - is more general
 and there are some contexts where = doesn't work, because I'm
 not trying to be absolutely rigorous, nor teach all the possible
 ins and outs of R syntax. I would be very surprised if any of
 the examples given actually came up in the course of a first-semester
 statistics/modeling R course.

I teach the idiom

summary(fm1 - lm(y ~ x, mydata))

in my introductory courses.

 I just want to do what works best for
 the students -- the problem is deciding on the balance between
 short term benefit (- is one more odd thing to get used to)
 and long term benefit (they will see - in other contexts, so
 they might as well get used to it eventually).

  Ben Bolker

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


__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Possible to write text inside a bar of a barplot?

2010-01-15 Thread Rex C. Eastbourne
Thanks for the replies! The answer is that barplot() returns the x
coordinates of the bars.

On Fri, Jan 15, 2010 at 12:01 PM, Rex C. Eastbourne 
rex.eastbou...@gmail.com wrote:

 How can I write text inside a bar of a barplot? I tried using text(), but I
 am only able to specify the numeric y-coordinate. The different columns of
 my barplot correspond to factors and not numbers, so I don't know how to
 access the horizontal positions of the bars. I tried fiddling with different
 values of the adj argument, but this appears unreliable.

 Background: I have created a barplot visualization where the bars represent
 the size of different items (e.g. US state populations), and the sub-bars
 represent the size of the different sub-components of each item (e.g.
 counties). Picture: http://drop.io/hjcodjj/asset/capture-png

 I would like to put in a label inside each sub-bar (e.g. indicating the
 name of the county represented by that sub-bar).

 Rex

 p.s.: In case anyone finds this visualization useful I'll share my code
 afterward, but just need to get the labeling working properly first.


[[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] Eigenvectors and values in R and SAS

2010-01-15 Thread Juliet Hannah
Here is an example that may be helpful.

A - matrix(c(-3,5,4,-2),nrow=2,byrow=TRUE)
eigs - eigen(A)

eigs

$values
[1] -7  2

$vectors
   [,1]   [,2]
[1,] -0.7808688 -0.7071068
[2,]  0.6246950 -0.7071068

The eigenvectors may be scaled differently because they are not unique
(or have a different sign), but Ax = lambda x, for an eigenvalue
lambda.

#Ax
A %*% eigs$vectors[,1]

  [,1]
[1,]  5.466082
[2,] -4.372865

# λx
 -7 * eigs$vectors[,1,drop=FALSE]
  [,1]
[1,]  5.466082
[2,] -4.372865


The eigenvectors for proc iml are scaled similarly, but have different signs.

proc iml;
A = {-3 5, 4 -2};
print A;
eigval = eigval(A);
evec = eigvec(A);
print eigval;
print evec;

A_x = A*evec[,1];
lambda_x = eigval[1,1]*evec[,1];
print A_x;
print lambda_x;

quit;

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

2010-01-15 Thread Greg Snow
As a general rule, you really do not want to edit graphs by 
pointing/clicking/dragging.  It may seem an easy way to make some 
modifications, but in the long run it will become more of a headache than a 
help.  Better to create a script with the commands to create the plot, then if 
there is some change you want made, find the correct change or addition to the 
script and rerun the script.  That way when later on you have a similar project 
and want to create the same or similar graph, you can just run the script again 
with the new data, making any minor changes that you need.

On the other hand if you create the basic plot then edit it using 
point/click/drag style tools, then a couple months later when you find that 
there was a typo in the data and you need to recreate the graph (not as rare an 
event as we would like), you will first need to remember how you created the 
graph, then you will need to remember all the point/click/drag steps that you 
took (and redo them).  It is just simpler to use the script.

Having said that, if you still feel the need to modify a plot using a mouse 
(don't complain when you have to redo all the steps to redo the graph) then 
some options include:

Save the graph as an svg file (Cairo device, or other package) then use 
inkscape or other program to edit it.
Save the graph as a fig file and use xfig/winfig/jfig to edit it.
Save/copy the graph as a windows meta file and use Excel/Word to edit it.

But the R paradigm is really to use a script to create the correct graph in the 
first place rather than give an incorrect graph and expect the user to use 
non-reproducible post-hoc modifications.

Hope this helps,

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


 -Original Message-
 From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-
 project.org] On Behalf Of vikrant
 Sent: Friday, January 15, 2010 2:27 AM
 To: r-help@r-project.org
 Subject: [R] Can I save R graphs as a R objects
 
 
 Can I save R graphs as a R objects ? IF yes then if I click this R
 object
 can I edit my chart as in Excel.
 Please suggest your views
 --
 View this message in context: http://n4.nabble.com/Can-I-save-R-graphs-
 as-a-R-objects-tp1014621p1014621.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] randomForest maxnodes

2010-01-15 Thread Epic John
Has anyone sucessfully used the maxnodes feature in randomForest? I tried
setting it, but when it is non-NULL I always get back a forest in which all
trees have size 1. I am using a continuous response (regression). Any help
would be appreciated.
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.


Re: [R] (no subject)

2010-01-15 Thread milton ruser
Saleem,

I have no idea about this, but may be you can use other data.frame name
instead of data because data is a name of a function (see ?data).

good luck

milton
On Fri, Jan 15, 2010 at 3:33 PM, saleem mukhtar saleem...@yahoo.com wrote:

 Hello,

 I am running R on cygwin for windows.

 File R1234 contains

 data - read.table(data)
 q()

 On the command line I type

 R --no-save -q R_PROFILE=R1234

 returns

 Error: could not find function read.table

 THanks.

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


[[alternative HTML version deleted]]

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


[R] weighting (survey) data

2010-01-15 Thread vivi ane
Hi,

is there a function in R equivalent to the weight by-command in SPSS?
I'm working with survey datasets and the data need to be weighted by a
survey/ probability/ design weight (to compensate for different
probabilities to be included in the sample in each country). The
weight variables are included in the datasets.

I did find functions in the Hmisc and survey packages that might fit
some of my needs but I need to do a bunch of procedures for all of
which the data must be weighted, as far as I can see. (I'm quite new
to R and the prospect of having to write my own functions for all of
them is really scaring me ;))

Thanks,
Vera

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

2010-01-15 Thread David Winsemius


On Jan 15, 2010, at 5:13 PM, vivi ane wrote:


Hi,

is there a function in R equivalent to the weight by-command in  
SPSS?

I'm working with survey datasets and the data need to be weighted by a
survey/ probability/ design weight (to compensate for different
probabilities to be included in the sample in each country). The
weight variables are included in the datasets.

I did find functions in the Hmisc and survey packages that might fit
some of my needs but I need to do a bunch of procedures for all of
which the data must be weighted, as far as I can see. (I'm quite new
to R and the prospect of having to write my own functions for all of
them is really scaring me ;))


RSiteSearch(survey)

--
David Winsemius, MD
Heritage Laboratories
West Hartford, CT

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


Re: [R] (no subject)

2010-01-15 Thread Bert Gunter
?Startup 
Read this help page **carefully**. It tells you what happens when R starts
up. The profile file is executed with **only the base package loaded**, and
read.table is not in the base package.

If you replace your read statement with 

data - utils::read.table(data)

it would work (if there is a data file in the working directory. Otherwise
it will fail because it can't find data). (The use of the name data for
an R object is bad form, as Milton mentioned. But it is not the cause of
your problem).

Query to core team: As this seems to have come up several times recently,
should this be in the FAQ in a question like:

Why can't R find the function called in my Profile file when R starts up?

(I'd be happy to write a first draft if so).

Bert Gunter
Genentech Nonclinical Biostatistics
 
 

-Original Message-
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On
Behalf Of milton ruser
Sent: Friday, January 15, 2010 2:07 PM
To: saleem mukhtar
Cc: r-help@r-project.org
Subject: Re: [R] (no subject)

Saleem,

I have no idea about this, but may be you can use other data.frame name
instead of data because data is a name of a function (see ?data).

good luck

milton
On Fri, Jan 15, 2010 at 3:33 PM, saleem mukhtar saleem...@yahoo.com wrote:

 Hello,

 I am running R on cygwin for windows.

 File R1234 contains

 data - read.table(data)
 q()

 On the command line I type

 R --no-save -q R_PROFILE=R1234

 returns

 Error: could not find function read.table

 THanks.

 __
 R-help@r-project.org mailing list
 https://stat.ethz.ch/mailman/listinfo/r-help
 PLEASE do read the posting guide

http://www.R-project.org/posting-guide.htmlhttp://www.r-project.org/posting
-guide.html
 and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

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

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

2010-01-15 Thread Liaw, Andy
Please try to follow the posting guide and give a reproducible example,
as below:

R library(randomForest)
randomForest 4.5-34
Type rfNews() to see new features/changes/bug fixes.
R iris2 = iris[-5]
R iris.rf = randomForest(Petal.Width~., iris2, maxnodes=4, ntree=50)
R nodesize(iris.rf)
Error: could not find function nodesize
R treesize(iris.rf)
 [1] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
4 4 4 4
[39] 4 4 4 4 4 4 4 4 4 4 4 4

Andy
 

 -Original Message-
 From: r-help-boun...@r-project.org 
 [mailto:r-help-boun...@r-project.org] On Behalf Of Epic John
 Sent: Friday, January 15, 2010 4:50 PM
 To: r-help@r-project.org
 Subject: [R] randomForest maxnodes
 
 Has anyone sucessfully used the maxnodes feature in 
 randomForest? I tried
 setting it, but when it is non-NULL I always get back a 
 forest in which all
 trees have size 1. I am using a continuous response 
 (regression). Any help
 would be appreciated.
 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.
 
Notice:  This e-mail message, together with any attachme...{{dropped:10}}

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

2010-01-15 Thread Stephan Kolassa

Hi Aaron,

try the argument statistic=mean. Then boot() will give you the mean 
turn angle in your actual data (which appears to be 6 degrees, judging 
from what you write), as well as the means of the bootstrapped data. 
Then you can get (nonparametric) bootstrap CIs by 
quantile(boot$t,probs=c(.025,.975)). As far as I can see, there is 
really no need to look at sd().


A more interesting question would be how to deal with the fact that 
-180=+180, there may be something to think about here...


HTH,
Stephan


aaron.fo...@students.tamuk.edu schrieb:

Hi All,

 


I'm new to R so please bear with me.  I have a dataset with 337 turn angles 
ranging from -180 to 180 degrees.  I need to bootstrap (sample with replacement) 
1,000 times to create expected average turn angle with 95% CIs.  The code is 
pretty straightforward (-boot(data =, statistic = ,R =)) but I am unsure how 
to input my observed mean (6 degrees) and standard deviation (66 degrees) into the 
statistic component.   I realize there is a 'function' code but I can't seem to 
carry the results over to the 'boot' code.

 


Thanks,

Aaron M. Foley
PhD Candidate
Caesar Kleberg Wildlife Research Institute
Texas AM University - Kingsville
Cousins Hall, Room 201
Kingsville, TX 78363



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


  1   2   >