[R] need help in understanding R code, and maybe some math

2010-05-22 Thread john smith
Hi,
I am trying to implement Higham's algorithm for correcting a non positive
definite covariance matrix.
I found this code in R:
http://projects.cs.kent.ac.uk/projects/cxxr/trac/browser/trunk/src/library/Recommended/Matrix/R/nearPD.R?rev=637

I managed to understand most of it, the only line I really don't understand
is this one:
X <- tcrossprod(Q * rep(d[p], each=nrow(Q)), Q)

This line is supposed to calculate the matrix product Q*D*Q^T, Q is an n by
m matrix and R is a diagonal n by n matrix. What does this mean?
I also don't understand the meaning of a cross product between matrices, I
only know it between vectors.

Thanks,
Barisdad.

[[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] Increasing the maximum number of rows

2010-05-22 Thread Wu Gong

Might there be a limit ?

> c <- matrix(1:1, ncol=200)
> dim(c)
[1] 50200
> c <- matrix(1:10, ncol=200)
Error: cannot allocate vector of size 3.7 Gb


-
A R learner.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Increasing-the-maximum-number-of-rows-tp2226950p2227578.html
Sent from the R help mailing list archive at Nabble.com.

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


Re: [R] Error in FUN(X[[1L]], ...) : STRING_ELT() can only be applied to a 'character vector', not a 'integer'

2010-05-22 Thread sedm1000

Sorry - I figured that this to be a more common defined error than anything
specific to the data/function...  Thanks for looking at this.

The data and function are below. Creating a single line of the data.frame at
a time will work (i.e. fold(s))

For multiple line data.frames, an error is generated. Ideally I would like
to record the output from fold(sq) in a two column data.frame, whether it
requires reading in the data to fold one line at a time or in bulk.

> library(GeneRfold)
> s<- "ATTATGCATCGACTAGCATCACTAG"
> fold(s)
[[1]]
[1] "....."

[[2]]
[1] -2.3


> sq <- data.frame(c("ATGTGTGATATGCATGTACAGCATCGAC",
+   "ACTAGCACTAGCATCAGCTGTAGATAGA",
+   "ACTAGCATCGACATCATCGACATGATAG",
+   "CATCGACTACGACTACGTAGATAGATAG",
+   "ATCAGCACTACGACACATAGATAGAATA"))

>fold(sq)
Error in fold(sq) : 
  STRING_ELT() can only be applied to a 'character vector', not a 'list'

> struct <- t(as.data.frame(sapply(sq[,1], fold, t=37)))

Error in FUN(X[[1L]], ...) :
 STRING_ELT() can only be applied to a 'character vector', not a 'integer'


>dput(fold,file="fred123")

function (s, t = 37) 
{
.Call("foldR", s, t, PACKAGE = "GeneRfold")
}

> dput(sq)
structure(list(c..ATGTGTGATATGCATGTACAGCATCGACACTAGCACTAGCATCAGCTGTAGATAGA...
= structure(c(4L, 
1L, 2L, 5L, 3L), .Label = c("ACTAGCACTAGCATCAGCTGTAGATAGA",
"ACTAGCATCGACATCATCGACATGATAG", 
"ATCAGCACTACGACACATAGATAGAATA", "ATGTGTGATATGCATGTACAGCATCGAC", 
"CATCGACTACGACTACGTAGATAGATAG"), class = "factor")), .Names =
"c..ATGTGTGATATGCATGTACAGCATCGACACTAGCACTAGCATCAGCTGTAGATAGA...",
row.names = c(NA, 
-5L), class = "data.frame")

> dput(s)
"ATTATGCATCGACTAGCATCACTAG"

> sessionInfo()
R version 2.11.0 (2010-04-22)
i386-apple-darwin9.8.0

locale:
[1] en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

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

other attached packages:
[1] GeneRfold_1.6.0 GeneR_2.18.0

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

-- 
View this message in context: 
http://r.789695.n4.nabble.com/Error-in-FUN-X-1L-STRING-ELT-can-only-be-applied-to-a-character-vector-not-a-integer-tp2226811p2227512.html
Sent from the R help mailing list archive at Nabble.com.

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


[R] Selecting first 7 elements

2010-05-22 Thread Kang Min
Hi,

I have a list of 100, each list has 20 elements, and I would like to
select the first 7 elements in each list.
Let's take the alphabet as an example.

x <- lapply(1:100, function(i) sample(LETTERS))

I tried x[[1:7]], but it doesn't work. Can anyone enlighten me on how
to do such selections?

Thank you.

Kang Min

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


Re: [R] User R to create MySQL database and table

2010-05-22 Thread Prof Brian Ripley

On Sat, 22 May 2010, Waverley @ Palo Alto wrote:


Hi,

I am thinking about using R to create a database, then create table in
MySQL server.  Can I do that using RMySQL package?


Maybe: it is done by SQL commands which you can use *if* you have the 
correct privileges.


However, this is R-help, not R-sig-db and discussion of non-R 
programming questions in detail would not be appropriate.  If you do 
want to follow up on R-sig-db, do first study the R posting guide and 
provide the 'at a minimum' information requested.




I am familiar with RMySQL, and in the online help most of the sample
code assumes the database exists and transact with the table inside
the database.

Can someone provide me some sample code to create a database and
table?  Specifically create a database first, then create a table
inside the database.

Thanks a lot in advance.

--
Waverley @ Palo Alto

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



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

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


Re: [R] Fast Matrix Computation

2010-05-22 Thread Jorge Ivan Velez
Yes, it should be. Thank you for pointing that out. Apologies for the noise.

Regards,
Jorge


On Sun, May 23, 2010 at 1:07 AM, Berend Hasselman <> wrote:

>
>
> Jorge Ivan Velez wrote:
> >
> > # The same using a function foo
> > foo <- function(A, B){
> >   rA <- 1:nrow(A)
> >   rB <- 1:nrow(B)
> >   grid <- as.matrix(expand.grid(rA, rB))
> >   t(apply(grid, 1, function(x) abs(A[x[1], ] - B1[x[2], ])))
> >  }
> >
> > foo(A, B)
> > foo(A, B1)
> >
> > As usual, there might be better and faster ways to do this.
> >
> > HTH,
> > Jorge
> >
>
> Shouldn't the B1 in the last line of the function 'foo' be B (the second
> argument of the function)?
>
> Berend
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Fast-Matrix-Computation-tp2227321p2227624.html
> Sent from the R help mailing list archive at Nabble.com.
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] Fast Matrix Computation

2010-05-22 Thread Berend Hasselman


Jorge Ivan Velez wrote:
> 
> # The same using a function foo
> foo <- function(A, B){
>   rA <- 1:nrow(A)
>   rB <- 1:nrow(B)
>   grid <- as.matrix(expand.grid(rA, rB))
>   t(apply(grid, 1, function(x) abs(A[x[1], ] - B1[x[2], ])))
>  }
> 
> foo(A, B)
> foo(A, B1)
> 
> As usual, there might be better and faster ways to do this.
> 
> HTH,
> Jorge
> 

Shouldn't the B1 in the last line of the function 'foo' be B (the second
argument of the function)?

Berend
-- 
View this message in context: 
http://r.789695.n4.nabble.com/Fast-Matrix-Computation-tp2227321p2227624.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] Bernoulli random variable with different probability

2010-05-22 Thread Jorge Ivan Velez
Hi Carrie,

Use the first approach:

n <- 5
p <- c(0.2, 0.9, 0.15, 0.8, 0.75)
rbinom(n, 1, p)
# [1] 0 0 0 1 1
rbinom(n, 1, p)
# [1] 1 1 0 1 1

To check, replicate the analysis 5000 times and then estimate the
probability for each subject:

rowMeans(replicate(5000, rbinom(n, 1, p)))
# 0.2002 0.9026 0.1550 0.8020 0.7562

Using Erik's solution you will get the "same" results:

> rowMeans(replicate(5000, sapply(p, function(x) sample(0:1, 1, prob =
c(1-x, x)
# [1] 0.1958 0.9006 0.1492 0.8066 0.7446

Note that in both cases the result is close to the original values of p.

HTH,
Jorge


On Sat, May 22, 2010 at 10:52 PM, Carrie Li <> wrote:

> Dear R-helpers,
>
> I would like to generate a variable that takes 0 or 1, and each subject has
> different probabilities of taking the draw.
>
> So, which of the following code I should use ?
>
> suppose there are 5 subjects, and their probabilities of this Bernoulli
> variable is  p=c(0.2, 0.9, 0.15, 0.8, 0.75)
> n<-5
> Ber.var <- rbimon(n,1,p) ## I doubt if this will take the first
> probability,
> which is 0.2, but won't change for each subject ??
>
> ## or should I use
> Ber.var <- sample(c(0,1), n, prob=p, replace=TRUE)
>
> Or any suggestions on how I can check if the probability of drawing this
> binary variable is based on the subject's probabilities ?
>
> Thanks for help!!
>
> Carrie
>
>[[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] Bernoulli random variable with different probability

2010-05-22 Thread Erik Iverson

Carrie Li wrote:

Dear R-helpers,

I would like to generate a variable that takes 0 or 1, and each subject has
different probabilities of taking the draw.

So, which of the following code I should use ?




I don't think either.

Try this:

probs <- seq(0,1, by = .1)
sapply(probs, function(x) sample(0:1, 1, prob = c(1-x, x)))

probs will be the vector of your probabilities for obtaining a '1' per subject, 
so set that to whatever you want, then run the second line.


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

2010-05-22 Thread Mohan L
Dear All,

I have an array some thing like this:

> avglog
  January  February March April   May  June  July
August September
60102 83397 56774 48785 49010 40572 38175
47037 51402

The class of "avglog" array.
> class(avglog)
[1] "array"

> str(avglog)
 num [1:9(1d)] 60102 83397 56774 48785 49010 ...
 - attr(*, "dimnames")=List of 1
  ..$ : chr [1:9] "January" "February" "March" "April" ...

I have to normalize this "avglog" array to 1000. I mean, I need to devide
1000/avglog[1] and have to multiply this to all the elements in the array
and need to plot graph Month Vs Index. To achive this I am doing the below
code. I am feeling there may be a simple way to do this.

> value <- matrix (avglog)

> value
   [,1]
 [1,] 60102
 [2,] 83397
 [3,] 56774
 [4,] 48785
 [5,] 49010
 [6,] 40572
 [7,] 38175
 [8,] 47037
 [9,] 51402

> day1Avg <- value[1]
> day1Avg
[1] 60102
> ID <- (1000/day1Avg)
> ID
[1] 0.01663838
> index <- value*ID
> index
   [,1]
 [1,] 1000.
 [2,] 1387.5911
 [3,]  944.6275
 [4,]  811.7034
 [5,]  815.4471
 [6,]  675.0524
 [7,]  635.1702
 [8,]  782.6195
 [9,]  855.2461

> monthcount <- length(avglog)

> Month <-  c(1:monthcount)

> trend <- cbind(Month,c(index))

> colnames(trend) <- c("Month","Index")

> trend
   Month  Index
 [1,]1 1000.
 [2,]2 1387.5911
 [3,]3  944.6275
 [4,]4  811.7034
 [5,]5  815.4471
 [6,]6  675.0524
 [7,]7  635.1702
 [8,]8  782.6195
 [9,]9  855.2461

any help will be greatly appreciated.

Thanks & Rg
Mohan L

[[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] Bernoulli random variable with different probability

2010-05-22 Thread Carrie Li
Dear R-helpers,

I would like to generate a variable that takes 0 or 1, and each subject has
different probabilities of taking the draw.

So, which of the following code I should use ?

suppose there are 5 subjects, and their probabilities of this Bernoulli
variable is  p=c(0.2, 0.9, 0.15, 0.8, 0.75)
n<-5
Ber.var <- rbimon(n,1,p) ## I doubt if this will take the first probability,
which is 0.2, but won't change for each subject ??

## or should I use
Ber.var <- sample(c(0,1), n, prob=p, replace=TRUE)

Or any suggestions on how I can check if the probability of drawing this
binary variable is based on the subject's probabilities ?

Thanks for help!!

Carrie

[[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] quick question on ftp access

2010-05-22 Thread steven mosher
I'm looking for a function or package that will allow me to get a list of
the files at an ftp site.
RCurl looks promising. Are there other packages that have similar
functionality

[[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] User R to create MySQL database and table

2010-05-22 Thread Waverley @ Palo Alto
Hi,

I am thinking about using R to create a database, then create table in
MySQL server.  Can I do that using RMySQL package?

I am familiar with RMySQL, and in the online help most of the sample
code assumes the database exists and transact with the table inside
the database.

Can someone provide me some sample code to create a database and
table?  Specifically create a database first, then create a table
inside the database.

Thanks a lot in advance.

-- 
Waverley @ Palo Alto

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Modeling time varying effects in with cph: how to ?

2010-05-22 Thread Marco Barbàra

Dear R users,

I know, this is the second time i return on this topic. Sorry, but this
analysis is of great value for me, and i hope someone can help me.

I need to model a time-varying effect in a Cox model. Briefly explained
here:

http://books.google.com/books?id=9kY4XRuUMUsC&lpg=PP1&hl=it&pg=PA147#v=onepage&q&f=false

http://finzi.psych.upenn.edu/R/Rhelp02/archive/52828.html

It seems that SAS is more well-suited to this purpose, as explained
in the links above, but i do not have enough time to learn SAS.  
I think i should use something like this:

cph(Surv(start,end,status)~a.factor+a.factor:start)

but i'm not sure, specially after Thernau's reply to my previous post.

Assuming i'm doing well, i'd prefer to use cph because of the
rms bootstrap validation facilities.

Unfortunately cph doesn't wanto to model an interaction term without
the both corresponding main effects: 

> fit.cph <- cph(TACE.Surv~PS+PS:TIME.start,data=DatasetTACE.imputati)
Error in if (!length(fname) || !any(fname == zname)) { : 
  missing value where TRUE/FALSE needed

coxph runs without complaining.

I could make the design matrix columns by hand, but this is generally
not recommended, isn't it?

Any sort of comment will be appreciated.

Thank you very much.

Marco Barbàra.

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


Re: [R] Regression with sparse matricies

2010-05-22 Thread Frank E Harrell Jr

On 05/22/2010 02:19 PM, Robin Jeffries wrote:

I would like to run a logistic regression on some factor variables (main
effects and eventually an interaction) that are very sparse. I have a
moderately large dataset, ~100k observations with 1500 factor levels for one
variable (x1) and 600 for another (X2), creating ~19000 levels for the
interaction (X1:X2).

I would like to take advantage of the sparseness in these factors to avoid
using GLM. Actually glm is not an option given the size of the design
matrix.

I have looked through the Matrix package as well as other packages without
much help.

Is there some option, some modification of glm, some way that it will
recognize a sparse matrix and avoid large matrix inversions?

-Robin



Robin,

It is doubtful that fixed effects are appropriate for your situation, 
but if you do want to use them there is experimental code in the lrm 
function in the rms package to handle "strat" (strata) factors that 
makes use of the sparse matrix representation.  Not sure if it handles 
more than one factor, and you'll have to play with the code to make sure 
this method is activated.  Take a look at lrm.fit.strat.s that comes 
with the source package, the see what is needed in lrm to use it.


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] Posting an 'S4-creating Package Problem'...

2010-05-22 Thread Daniel Kosztyla


After trying again your solution finally it worked with the collate field
in the DESCRIPTION file. The Warnings disappeared.
So indeed I have to thank you very much. Best wishes... Dan


On Sun, 7 Feb 2010, Martin Morgan wrote:


On 02/06/2010 03:39 PM, Daniel Kosztyla wrote:

Hello R-Team,

May you help me to post a 'S4-creating Package Problem'?
Thanks already now for supporting.
The problem sounds like:

Hello R forum,

while compiling my R-package these 'Warnings' occur:

...
Warnung in matchSignature(signature, fdef, where) :
  in the method signature for function "plot" no definition for class:
"prediction"
Warnung in matchSignature(signature, fdef, where) :
  in the method signature for function "plot" no definition for class:
"validation"
** help
*** installing help indices
...

Maybe my NAMESPACE file looks wrong. Has anybody an idea how it has to
look like to solve
this problem? ( I use exportClasses(...), exportMethods(...). )

I have 3 classes: 'prediction', 'validation', 'nvalidation' which have a
plot function.
There's no warning for class 'nvalidation' but for the other two.
Any suggestions?


Hi Dan

Files in a package are collated and then sourced. If your 'prediction'
class is in prediction.R, and your plot method is in plot.R, then the
files will be collated plot.R, prediction.R, and the class definition
for prediction will be unknown when the plot method is defined. Use
Collate: in the DESCRIPTION file, or put class (and generic) definitions
in files that collate early, e.g., AllClasses.R, AllGenerics.R.

Hope that helps,

Martin


Greetings. Dan

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



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

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



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


[R] multiple imputation based on a condition

2010-05-22 Thread Gary Collins

Any suggestions on the following would be grateful.

I'm trying to impute data, where a fictitional dataset is defined as...

set.seed(110)
n <- 500
test <- data.frame(smoke_status = rbinom(n, 2, 0.6), smoke_amount = 
rbinom(n, 2, 0.5), rf1 = rnorm(n), rf2 = rnorm(n), outcome = rbinom(n, 
1, 0.3))


# smoke_status (0, 1, 2) is c("non-smoker, "ex-smoker", 
"current_smoker"), and

# smoke_amount (0, 1, 2) is c("light", "moderate", "heavy")
# rf1 and rf2 are two other risk factors (for illustration purposes - 
real data set has more risk factors)


# artificially NA some of these values
test$smoke_status[sample(1:nrow(test), 60)] <- NA
test$smoke_amount[sample(1:nrow(test), 60)] <- NA
test$rf1[sample(1:nrow(test), 50)] <- NA
test$rf2[sample(1:nrow(test), 50)] <- NA

I'm trying to impute all missing values, but I only want to impute 
smoke_amount if smoke_status==2 (i.e. they are a current smoker - makes 
no sense to impute smoke_amount if they do not smoke).  I can do this in 
STATA via the conditional option in ICE, but would prefer to keep this 
in R.  Any suggestions (if this is feasible via MICE, mi or Amelia)? I 
thought the passive imputation approach in MICE would be the way forward 
but I've so far been unsuccessful.


Thanks in advance.

Gary

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


Re: [R] Increasing the maximum number of rows

2010-05-22 Thread Alex Ruiz E.

Hi thank you both for your answers. 

I did verify that the number of rows in the csv is actually ~207,000,
both in the MySQL output and then directly in the csv file. The line
128328 looks exactly as all others above and below.

I tried the comment.char and quote parameters and it turns out that the
quote parameter worked. I appreciate the pointer.

Regards,
Alex



On Sat, 2010-05-22 at 08:04 -0400, jim holtman wrote: 
> You might also try setting the following parameters on read.csv:
> 
> comment.char='', quote=''
> 
> If you have a "#", this might cause missing data; also an unbalanced
> quote will cause missing lines.
> 
> On Sat, May 22, 2010 at 2:12 AM, Erik Iverson  wrote:
> > Alex Ruiz E. wrote:
> >>
> >> Dear R helpers,
> >>
> >> I created a somewhat big database (+206,700 rows) in MySQL and have
> >> exported into a csv file, but I can't open the whole thing in R. I am
> >> using:
> >>
> >>> base<-read.csv("/path/to/file.csv", header=F, sep="," nrows=206720)
> >>
> >> R doesn't complain but it only opens 128,328 observations (the number of
> >> columns corresponds to the original database):
> >>
> >>> dim(base)
> >>
> >> [1] 128328134
> >
> > Have you verified that file.csv does indeed contain the number of rows you
> > think it does? Can you go to line 128328 of the CSV file and look if it's
> > any different?
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/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] Fast Matrix Computation

2010-05-22 Thread Jorge Ivan Velez
Hi David,

Here are two suggestions, one that works for the example you provided and a
second one for a more general case.

# Your example
A <- matrix(c(1, 2, 3, 4, 5, 6), byrow=TRUE, ncol=3)
B <- matrix(c(7, 8, 9), byrow=TRUE, ncol=3)
t(abs(t(A) - as.vector(B)))

# More general case
B1 <- structure(c(7, 8, 10, 11, 8, 9, 11, 12, 9, 10, 12, 13), .Dim =
c(4L, 3L))
rA <- 1:nrow(A)
rB <- 1:nrow(B1)
grid <- as.matrix(expand.grid(rA, rB))
t(apply(grid, 1, function(x) abs(A[x[1], ] - B1[x[2], ])))

# The same using a function foo
foo <- function(A, B){
  rA <- 1:nrow(A)
  rB <- 1:nrow(B)
  grid <- as.matrix(expand.grid(rA, rB))
  t(apply(grid, 1, function(x) abs(A[x[1], ] - B1[x[2], ])))
 }

foo(A, B)
foo(A, B1)


As usual, there might be better and faster ways to do this.

HTH,
Jorge


On Sat, May 22, 2010 at 1:35 PM, David Neu <> wrote:

> Hi,
>
> I have two (large) matrices A and B of dimensions (m,n) and (p,n)
> respectively.
>
> I'd like to see if the is a fast way to compute a new matrix C with
> dimension (m*p,n) in which each row in C is found by applying some
> function f to each pair of rows (x,y) where x is a row in A and y is a
> row in B.
>
> For example, if
>
> A <- matrix(c(1, 2, 3, 4, 5, 6), byrow=TRUE, ncol=3)
> B <- matrix(c(7, 8, 9), byrow=TRUE, ncol=3)
>
> and f <- function(x,y) abs(y-x)
>
> then
>
> C <- matrix(c(6, 6, 6, 3, 3, 3), byrow=TRUE, ncol=3)
>
> Many thanks!
>
> Cheers,
> David
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] calling Perl script from R on Windows 7

2010-05-22 Thread Harsh
Hi list,
I would like to capture the console output of a Perl script by running the
script from R.
I have tried the following:

# Create perl script
cat( 'print "Hello World\n";',file="hello.pl" )

# Trial 1
system(command="c:\\Perl64\\bin\\perl hello.pl")

-I saw no output for the above command. I have used this method before to
run perl scripts that performed tasks, but only now do I want to capture the
perl output from the print command within the perl script

# Trial 2
system(command=paste(Sys.getenv("COMSPEC"),"/c","C:\\Perl64\\bin\\perl
hello.pl"))
- In the help for 'system' in R, it mentions making the above changes if one
wants to pass a command to the cmd on a windows machine.


I am using R 2.9.2 on Windows 7.

I'm doing this since I want to run perl scripts to find distance measures
between words (Wordnet Similarity perl modules) and capture the numeric
result from the perl script execution back into R. I have heard of RSPerl
but I would greatly appreciate a solution using system. Writing the result
to a file and then reading the file could be a another option, but I'd like
to learn about capturing console output from perl into R.


Any suggestions or hints would be appreciated with much gratitude.

Thanks
Harsh

[[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] quick question on getting a listing of files on ftp site

2010-05-22 Thread steven mosher
Given a valid ftp address, is there a package that will allow me to get a
listing of the files/directory structure
on that site? RCurl looks to have this ability are there others?

[[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] Fast Matrix Computation

2010-05-22 Thread Thomas Stewart
One possibility:

n.A<-nrow(A)
n.B<-nrow(B)

abs( kronecker(A,rep(1,n.B)) - kronecker(rep(1,n.A),B) )

-tgs

On Sat, May 22, 2010 at 3:20 PM, Shi, Tao  wrote:

> One way to do it:
>
> apply(B, 1, function(x) t(apply(A, 1, function(y) abs(y-x) )) )
>
>
>
>
>
> - Original Message 
> > From: David Neu 
> > To: r-help@r-project.org
> > Sent: Sat, May 22, 2010 10:35:32 AM
> > Subject: [R] Fast Matrix Computation
> >
> > Hi,
>
> I have two (large) matrices A and B of dimensions (m,n) and (p,n)
> > respectively.
>
> I'd like to see if the is a fast way to compute a new
> > matrix C with
> dimension (m*p,n) in which each row in C is found by applying
> > some
> function f to each pair of rows (x,y) where x is a row in A and y is
> > a
> row in B.
>
> For example, if
>
> A <- matrix(c(1, 2, 3, 4, 5, 6),
> > byrow=TRUE, ncol=3)
> B <- matrix(c(7, 8, 9), byrow=TRUE, ncol=3)
>
> and
> > f <- function(x,y) abs(y-x)
>
> then
>
> C <- matrix(c(6, 6, 6, 3,
> > 3, 3), byrow=TRUE, ncol=3)
>
> Many
> > thanks!
>
> Cheers,
> David
>
> __
>
> > ymailto="mailto:R-help@r-project.org";
> > href="mailto:R-help@r-project.org";>R-help@r-project.org mailing list
>
> > href="https://stat.ethz.ch/mailman/listinfo/r-help"; target=_blank
> > >https://stat.ethz.ch/mailman/listinfo/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.
>

[[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 find all single minima, i.e. only each one within each next part of analyzed vector (table)

2010-05-22 Thread Wu Gong

I hope this will help.

### Find rows with minimum value from every 5 rows
## Create the data
mlb <- data.frame(mass_position=c(1,2,3,4,5,6,7,8,9,10,
11,12,13,14,15,16,17,18,19,20),
mass_value=c(9,2,3,2,5,6,7,8,9,10,2.1,12, 1,14,15,16,17,18,19,20),

mass_label=c("lab1","lab2","lab3","lab4","lab5","lab6","lab7","lab8","lab9","lab10",

"lab11","lab12","lab13","lab14","lab15","lab16","lab17","lab18","lab19","lab20")
)

## Sort the data three times
## Create result by selecting first rows of every 5 rows 
mlb2 <- mlb[order(mlb[,1] %/% 5.1, mlb[,2], mlb[,1]),][mlb[,1] %% 5 == 1,]

## Exclude rows which mass_value > 2
(mlb3 <- mlb2[mlb2[,2] <= 2,])

-
A R learner.
-- 
View this message in context: 
http://r.789695.n4.nabble.com/How-to-find-all-single-minima-i-e-only-each-one-within-each-next-part-of-analyzed-vector-table-tp2227224p2227292.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] Fast Matrix Computation

2010-05-22 Thread Shi, Tao
One way to do it:

apply(B, 1, function(x) t(apply(A, 1, function(y) abs(y-x) )) )





- Original Message 
> From: David Neu 
> To: r-help@r-project.org
> Sent: Sat, May 22, 2010 10:35:32 AM
> Subject: [R] Fast Matrix Computation
> 
> Hi,

I have two (large) matrices A and B of dimensions (m,n) and (p,n) 
> respectively.

I'd like to see if the is a fast way to compute a new 
> matrix C with
dimension (m*p,n) in which each row in C is found by applying 
> some
function f to each pair of rows (x,y) where x is a row in A and y is 
> a
row in B.

For example, if

A <- matrix(c(1, 2, 3, 4, 5, 6), 
> byrow=TRUE, ncol=3)
B <- matrix(c(7, 8, 9), byrow=TRUE, ncol=3)

and 
> f <- function(x,y) abs(y-x)

then

C <- matrix(c(6, 6, 6, 3, 
> 3, 3), byrow=TRUE, ncol=3)

Many 
> thanks!

Cheers,
David

__

> ymailto="mailto:R-help@r-project.org"; 
> href="mailto:R-help@r-project.org";>R-help@r-project.org mailing list

> href="https://stat.ethz.ch/mailman/listinfo/r-help"; target=_blank 
> >https://stat.ethz.ch/mailman/listinfo/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] Regression with sparse matricies

2010-05-22 Thread Robin Jeffries
I would like to run a logistic regression on some factor variables (main
effects and eventually an interaction) that are very sparse. I have a
moderately large dataset, ~100k observations with 1500 factor levels for one
variable (x1) and 600 for another (X2), creating ~19000 levels for the
interaction (X1:X2).

I would like to take advantage of the sparseness in these factors to avoid
using GLM. Actually glm is not an option given the size of the design
matrix.

I have looked through the Matrix package as well as other packages without
much help.

Is there some option, some modification of glm, some way that it will
recognize a sparse matrix and avoid large matrix inversions?

-Robin

[[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] Lattice Wireframe Plot into LaTex

2010-05-22 Thread Peter Ehlers

Could be FAQ#7.22.

 -Peter Ehlers

On 2010-05-22 13:00, Lars Bishop wrote:

Dear R/LaTex user,

I'm simply trying to include a plot created with the Lattice wireframe
function into LaTex. I have no problems including other R plots into LaTex
by exporting as a Postcript and then including the graph in LaTex using

\begin{figure}
   % Requires \usepackage{graphicx}
   \includegraphics[width=]{mygraph.eps}\\
   \caption{}\label{}
\end{figure}
However, for some reason when I do this with a wireframe plot I can see the
plot area in LaTex but not the plot itself.

I've search for this exhaustively on the web but couldn't find an answer.

I'll appreciate your help.

Thanks,
Lars.

[[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] escape character OK in R environment, fails in R CMD CHECK

2010-05-22 Thread David Reiss
Ah, you are right, it is in one of my Rd file, not in my actual code.
Sorry for the misunderstanding, and thanks for the solution.

-David

2010/5/22 Uwe Ligges 

>
>
> On 22.05.2010 08:18, Henrik Bengtsson wrote:
>
>> R version/sessionInfo()?
>>
>> /H
>>
>> On Fri, May 21, 2010 at 10:08 PM, David Reiss
>>  wrote:
>>
>>> Hi,
>>> I am trying to check a package via R CMD CHECK and it is failing with
>>>
>>> Error: '\s' is an unrecognized escape in character string starting "\s"
>>>
>>> The culprit looks something like this:
>>>
>>> gsub('\\s\\(.*\\)',"","this is a (test, man) dude")
>>>
>>
>
> I guess this is in the Examples of an Rd document, right? If so, you need
> to double escape, i.e.:
>
>  gsub('s(.*)',"","this is a (test, man) dude")
>
> Uwe Ligges
>
>
>
>
>
>
>  which is correctly escaped with the "\\"'s   -- but it seems that R CMD
>>> CHECK is pre-escaping the string when it reads in the code to check it.
>>>
>>> How do I get R CMD CHECK to let the "\\s" 's through?
>>>
>>> Thanks.
>>>
>>>[[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>> __
>> R-help@r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

[[alternative HTML version deleted]]

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


[R] Lattice Wireframe Plot into LaTex

2010-05-22 Thread Lars Bishop
Dear R/LaTex user,

I'm simply trying to include a plot created with the Lattice wireframe
function into LaTex. I have no problems including other R plots into LaTex
by exporting as a Postcript and then including the graph in LaTex using

\begin{figure}
  % Requires \usepackage{graphicx}
  \includegraphics[width=]{mygraph.eps}\\
  \caption{}\label{}
\end{figure}
However, for some reason when I do this with a wireframe plot I can see the
plot area in LaTex but not the plot itself.

I've search for this exhaustively on the web but couldn't find an answer.

I'll appreciate your help.

Thanks,
Lars.

[[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] Data reconstruction following PCA using Eigen function

2010-05-22 Thread Thomas Stewart
Looks like you have some numerical precision issues.  Why not use the svd
function directly?  (See below.)

-tgs

x <- read.table(
textConnection(
"Sample1   0.7329881  0.76912670  2.45906143 -0.06411602  1.2427801
0.3785717  2.34508664  1.1043552 -0.1883830  0.6503095
Sample2  -2.0446131  1.72783245 -0.40965941 -0.21713655 -0.2386781
-0.1944390 -0.25181541  0.8882743  0.8404783  0.2531209
Sample3   1.7575174  0.03851425 -0.87537424  1.82811160  0.8342636
-0.8155942 -0.90893068 -0.5529098 -1.6586626  0.1761717
Sample4   0.2731749  0.24045167 -0.39913821 -0.48525909  0.1448994
-2.0173360 -0.01073639 -0.3219478 -1.1536431 -0.2521545
Sample5  -0.2014241 -1.04646151  0.28101160  0.74348390  0.1738312
-0.8431262 -0.08842512  1.2909658  1.2013136  0.6706926
Sample6   0.1743534 -1.70657357 -0.09170187 -0.55605031 -0.2940946 1.4525891
-0.39068509 -0.3373913 -0.0533732  0.9658389
Sample7  -0.8533191 -0.34438091 -1.23890437 -0.77360636  0.5926479 0.7742632
-1.12515017 -0.5720099  0.2243808  0.5420693
Sample8   0.4176988 -0.35906123 -0.07190644  0.90045123 -1.0621902 0.2693762
-0.38033715  0.6267548  0.4767652  0.3012347
Sample9   0.1088066 -0.32197951  0.46665158 -1.72560781  0.7375796 0.2794331
 1.00171777 -0.1087306  1.2519195 -0.8848459
Sample10 -0.3651829  1.00253167 -0.12004007  0.34972942 -2.1310389 0.7162622
-0.19072440 -2.0173607 -0.9407956 -2.4224372"),
 header=F, as.is=TRUE)

X<-as.matrix(x[,-1])

V <- t( eigen( t(X) %*% X , T )$vectors )
U <- eigen( X %*% t( X ) , T )$vectors
D <- diag( sqrt( eigen( X %*% t( X ) , T )$values ) )

X - U %*% D %*% t(V)

svd(X)$v - V
svd(X)$u - U
svd(X)$d - sqrt( eigen( X %*% t( X ) , T )$values )

X-svd(X)$u %*% diag( svd(X)$d ) %*% t( svd(X)$v )






On Fri, May 21, 2010 at 2:25 PM, Julia El-Sayed Moustafa <
jelsa...@imperial.ac.uk> wrote:

>
> Hi all,
>
> As a molecular biologist by training, I'm fairly new to R (and
> statistics!),
> and was hoping for some advice. First of all, I'd like to apologise if my
> question is more methodological rather than relating to a specific R
> function. I've done my best to search both in the forum and elsewhere but
> can't seem to find an answer which works in practice.
>
> I am carrying out principal component analysis in R using the Eigen
> function, and have applied this to my dataset and can identify patterns in
> my data which result from batch effects. What I'd ultimately like to do is
> use PCA as a noise filter to remove the batch effects from my data, and the
> way I would like to try and do this is by reconstructing the data, minus
> the
> components (or that part of them) which correlate with batch.
>
> As I have an extremely large dataset, as a first step I am attempting
> simply
> to apply the Eigen function to a dummy dataset consisting of only 10
> individuals and ten variables derived from my originial data, then
> reconstruct the original dummy data matrix, just to see if I can get the
> basics of the method to work first. Here is the dummy matrix (adjusted by
> variable mean-subtraction and division by the variable standard deviation
> applied to each data point) I am using:
>
> adjusted_dummyset
>   [,1][,2][,3][,4]   [,5]
> [,6][,7]   [,8]   [,9]  [,10]
> Sample1   0.7329881  0.76912670  2.45906143 -0.06411602  1.2427801
> 0.3785717  2.34508664  1.1043552 -0.1883830  0.6503095
> Sample2  -2.0446131  1.72783245 -0.40965941 -0.21713655 -0.2386781
> -0.1944390 -0.25181541  0.8882743  0.8404783  0.2531209
> Sample3   1.7575174  0.03851425 -0.87537424  1.82811160  0.8342636
> -0.8155942 -0.90893068 -0.5529098 -1.6586626  0.1761717
> Sample4   0.2731749  0.24045167 -0.39913821 -0.48525909  0.1448994
> -2.0173360 -0.01073639 -0.3219478 -1.1536431 -0.2521545
> Sample5  -0.2014241 -1.04646151  0.28101160  0.74348390  0.1738312
> -0.8431262 -0.08842512  1.2909658  1.2013136  0.6706926
> Sample6   0.1743534 -1.70657357 -0.09170187 -0.55605031 -0.2940946
> 1.4525891 -0.39068509 -0.3373913 -0.0533732  0.9658389
> Sample7  -0.8533191 -0.34438091 -1.23890437 -0.77360636  0.5926479
> 0.7742632 -1.12515017 -0.5720099  0.2243808  0.5420693
> Sample8   0.4176988 -0.35906123 -0.07190644  0.90045123 -1.0621902
> 0.2693762 -0.38033715  0.6267548  0.4767652  0.3012347
> Sample9   0.1088066 -0.32197951  0.46665158 -1.72560781  0.7375796
> 0.2794331  1.00171777 -0.1087306  1.2519195 -0.8848459
> Sample10 -0.3651829  1.00253167 -0.12004007  0.34972942 -2.1310389
> 0.7162622 -0.19072440 -2.0173607 -0.9407956 -2.4224372
>
> I first multiply the matrix by the transposed matrix:
>
> > xxt=adjusted_dummyset %*% t(adjusted_dummyset)
> > xxt
>   Sample1Sample2Sample3Sample4Sample5Sample6
> Sample7Sample8Sample9   Sample10
> Sample1  16.045163 -1.1367278 -2.5390033 -1.4762231  1.0158736 -1.8408484
> -5.8176751 -1.5163240  3.5304834 -6.2647180
> Sample2  -1.136728  9.0985066 -5.2175085 -0.8332460  0.7980575 -3.3607995
> 1.6342076 -0.3098849 -0.3462389 -0.

[R] R for Stata Users

2010-05-22 Thread Muenchen, Robert A (Bob)
Dear R-Helpers,

If you know of any Stata users looking to learn R, our book "R for Stata
Users" finally shipped this week. A software snag delayed the printing
of all Springer books for quite a few weeks. A description of that book,
and reviews of its predecessor, "R for SAS and SPSS Users" is at
http://r4stats.com . The example programs and data files used by both
books are also at that site.

Cheers,
Bob Muenchen & Joe Hilbe

=
  Bob Muenchen (pronounced Min'-chen), Manager  
  Research Computing Support
  Voice: (865) 974-5230  
  Email: muenc...@utk.edu
  Web:   http://oit.utk.edu/research, 
  News:  http://oit.utk.edu/research/news.php
  Feedback: http://oit.utk.edu/feedback/
=

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

2010-05-22 Thread David Neu
Hi,

I have two (large) matrices A and B of dimensions (m,n) and (p,n) respectively.

I'd like to see if the is a fast way to compute a new matrix C with
dimension (m*p,n) in which each row in C is found by applying some
function f to each pair of rows (x,y) where x is a row in A and y is a
row in B.

For example, if

A <- matrix(c(1, 2, 3, 4, 5, 6), byrow=TRUE, ncol=3)
B <- matrix(c(7, 8, 9), byrow=TRUE, ncol=3)

and f <- function(x,y) abs(y-x)

then

C <- matrix(c(6, 6, 6, 3, 3, 3), byrow=TRUE, ncol=3)

Many thanks!

Cheers,
David

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


Re: [R] question about graph

2010-05-22 Thread John Kane
This is not enough information to let us give a good example but perhaps ?lines 
or ?points might help?



Example

aa <- 1:5
bb <- 1:5
cc <- c(1.5,2.5,3.5,4.2,4.4)
plot(aa,bb)
lines(aa,cc,col='red')
points(aa,cc, col="blue")


--- On Sat, 5/22/10, khaz...@ceremade.dauphine.fr 
 wrote:

> From: khaz...@ceremade.dauphine.fr 
> Subject: [R] question about graph
> To: r-help@r-project.org
> Received: Saturday, May 22, 2010, 5:53 AM
> Hi,
> 
> 
> I have two different sets of data from two different
> populations. I want
> to plot these samples (for example: Line graph) by just one
> graph.
> could you please help me?
> 
> Thanks
> Khazaei
> 
> __
> R-help@r-project.org
> mailing list
> https://stat.ethz.ch/mailman/listinfo/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] RWinEdt

2010-05-22 Thread Yves Aragon
I have installed RWinEdt but when I try to load it,  I get the message :

Error in normalizePath(path) :
  path[1]="C:\Users\yves\AppData\Roaming\WinEdt/R.ini": The specified file 
cannot be found.

I have the problem with R 2.11.0 and R 2.10.1,  since I have re-installed 
WinEdt.

Yves

[[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] ivreg postestimation

2010-05-22 Thread Dipankar Basu
Hi All,

I am trying to do an instrumental variables regression with time series data
in R 2.11.0. I am using the package AER and have so far used "ivreg" for
estimation. I would also like to do some postestimation tests: test for
endogeniety, test of overidentifying restrictions and test of weak
instruments.

I could do these in STATA by first estimating the model with "ivregress" and
then using (1) estat endogenous, (2) estat overid, (3) estat firststage.

Are there similar postestimation commands in the package AER or in some
other package in R?

Thanks.
Deepankar

[[alternative HTML version deleted]]

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


[R] How to find all single minima, i.e. only each one within each next part of analyzed vector (table)

2010-05-22 Thread Eugeniusz Kaluza
Dear R users,
How to find all single minima within each next part of analyzed vector (table)
Select all minima (mass_value=min & mass_value<2) 
(many) in vector(table), 
BUT first put mask on table in order to select 
within one window mask (5 elements) only one local minimum, and next to search 
within 
the next time window mask the second minimum (only one local along second mask)
 
mass_position<-c(1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20)
mass_value<-c(9,2,3,2,5,6,7,8,9,10,2.1,12, 1,14,15,16,17,18,19,20)
mass_label<-c("lab1","lab2","lab3","lab4","lab5","lab6","lab7","lab8","lab9","lab10",
   
"lab11","lab12","lab13","lab14","lab15","lab16","lab17","lab18","lab19","lab20")
 

dt<-5

# i.e.
 mass_value<-c   (9,0,3,1,5,6,7,8,3,10,2.1,12, 1, 1,15,16,17,18,19,20)
 mass_position<-c(1,2,3,4,5,6,7,8,9,10, 11,12,13,14,15,16,17,18,19,20)
# - - - - -   
#   1   x  first needed 
min= 0, pos=2
#(only one within first mask)  
#   - - - x  -
#   (min= 3, but & ( 3 is not <2)) =>there is not min 
for us locally

#-  -  -  -  -
#  1  x 2nd needed   
min=1,pos=13 
# not min=1 on position 14, because we want only 1 min locally 
#  and only one locally within each NEXT 5 elements)
#
#  .  .  .  .  . 

#correct answer would be vector :
# "lab2","lab13" 

#expected answer = 
local_min_positions = (2 ,13 ) 
local_min_values= (0 ,1  )
local_min_labels= ("lab2","lab13")

How to find labels from my_label:
for all localizations of different minima in mass, 
but within time window there can be only one minimum, 
i.e. in dt=5 second wide time window there can be only one minimum

Yours sincerely,
Eugen



[[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] university lessons in mathematical statistics

2010-05-22 Thread David Winsemius


On May 22, 2010, at 9:08 AM, Csaba Szigeti wrote:


Hi!

 I'm learning Mathematical Statistics at a hungarian university.

 My teacher, who teaches these lessons, using the R to introduce some
topics.

 I want to pass on the exam, and this exam contains some R questions  
too,
but the teacher doesn't thaught us too much about R, so I would like  
to ask

for some help from you in solving some example questions in R.

 So, here are some questions, that I'm looking answer for:
http://iaeste.elte.hu/attachment/prv_minta2.pdf . I translate these
questions into english:

  1. Interpret the following charts and describe the used method's
  substance.


Review your lecture notes:

http://www.cs.elte.hu/%7Ezempleni/elemstat3.pdf


  2. The figure and the sum (p) = 223 value are the result of the  
following
  lines of a program. What have we investigated? Interpret the  
results!


Your professor's major interest is in meteorology. That should be some  
sort of clue.



  3. Interpret the following result:


http://www.cs.elte.hu/%7Ezempleni/elemstat10.pdf

R-help is not a tutoring site.

--
David.

  ...

 Thanks for the answers in advance!

Regards,
Csaba Szigeti

[[alternative HTML version deleted]]

--
David Winsemius, MD
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] escape character OK in R environment, fails in R CMD CHECK

2010-05-22 Thread Uwe Ligges



On 22.05.2010 08:18, Henrik Bengtsson wrote:

R version/sessionInfo()?

/H

On Fri, May 21, 2010 at 10:08 PM, David Reiss  wrote:

Hi,
I am trying to check a package via R CMD CHECK and it is failing with

Error: '\s' is an unrecognized escape in character string starting "\s"

The culprit looks something like this:

gsub('\\s\\(.*\\)',"","this is a (test, man) dude")



I guess this is in the Examples of an Rd document, right? If so, you 
need to double escape, i.e.:

 gsub('s(.*)',"","this is a (test, man) dude")

Uwe Ligges






which is correctly escaped with the "\\"'s   -- but it seems that R CMD
CHECK is pre-escaping the string when it reads in the code to check it.

How do I get R CMD CHECK to let the "\\s" 's through?

Thanks.

[[alternative HTML version deleted]]

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



__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/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] Capturing R console output into a file (sink+savehistory ??)

2010-05-22 Thread Duncan Murdoch

Tal Galili wrote:

After reading more, I understand I didn't formulate my last question
correctly, so please allow me to rephrase:

What I am looking for is a way to save the R console session output.
That is, a command that would combine the results of using:
?sink   # And
?savehistory
  


I think there's still some ambiguity in the question; I'll try to answer 
a few versions.


Do you want to run R normally, then afterwards save the console log?  
That depends on what front end you're using.  In the Windows GUI, you 
can do it with
Ctrl-A to select everything in the console, then menu items File | Save 
to file..., or just Ctrl-C to copy, and then paste it into Word.  
Similar operations would work on a Mac.


Do you want to run code in a way that writes it to a file without 
displaying it to the screen?  R CMD batch does that.


Do you want to run just a few commands like that? Then try

capture.output(source(stdin(), echo=TRUE))

This will accept commands from the console until it hits an EOF (Ctrl-Z 
on Windows, I don't know on other systems, but Ctrl-D is a good guess) 
and will return

the results in a character vector, which you could write to a file.

Do you want to run R normally with output on screen, but also logging 
everything to a file?  I don't know how to do that in the R GUI in 
Windows, but there are probably command line tools that could do it.


Duncan Murdoch

  
My motivation for this is that doing it will allow someone who is a blind

user of R to be able to easily export his results to word so he could have
word read him the text.
I also imagine it might be useful for session login.

Thanks,
Tal




Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Sat, May 22, 2010 at 12:20 AM, Tal Galili  wrote:

  

Hi David,

I want to get both the 4 and the "1+3" that created it.

I am trying to help someone else on the mailing list that is looking for a
way to "sink" the console into word, so he could have word read it to him
(he is blind).
I know how to do the second part, but the first part (using sink with the
commands, and not just the output), I am somehow missing...

Best,
Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)

--




On Sat, May 22, 2010 at 12:17 AM, David Winsemius wrote:



On May 21, 2010, at 5:02 PM, Tal Galili wrote:

 Hi all,
  

I am trying to use type message with sink, like this:

sink("all.Rout", type="message")
1+3

sink()

readLines(con = "all.Rout")

So to get the following output:

 1+3

[1] 4


Obviously this doesn't work.




What are you trying to do? The sink help page has two rather dire warnings
about not using type="message",  and using type="output would give you what
you ask:

  

sink("all.Rout", type="output")

1+3


sink()

readLines(con = "all.Rout")


[1] "[1] 4"

The extra "[1]" and quotes are from the readLines function, not from
all.Rout.


 I tried some variations (based on the explanations in the help) but am
  

missing something on how to make it work.

Any suggestions?

(p.s: I need this so to help Faiz Rasool in his latest post)

Thanks,

Tal



--
David Winsemius, MD
West Hartford, CT


  


[[alternative HTML version deleted]]

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



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

2010-05-22 Thread Csaba Szigeti
Hi!

  I'm learning Mathematical Statistics at a hungarian university.

  My teacher, who teaches these lessons, using the R to introduce some
topics.

  I want to pass on the exam, and this exam contains some R questions too,
but the teacher doesn't thaught us too much about R, so I would like to ask
for some help from you in solving some example questions in R.

  So, here are some questions, that I'm looking answer for:
http://iaeste.elte.hu/attachment/prv_minta2.pdf . I translate these
questions into english:

   1. Interpret the following charts and describe the used method's
   substance.
   2. The figure and the sum (p) = 223 value are the result of the following
   lines of a program. What have we investigated? Interpret the results!
   3. Interpret the following result:
   ...

  Thanks for the answers in advance!

Regards,
Csaba Szigeti

[[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] Increasing the maximum number of rows

2010-05-22 Thread jim holtman
You might also try setting the following parameters on read.csv:

comment.char='', quote=''

If you have a "#", this might cause missing data; also an unbalanced
quote will cause missing lines.

On Sat, May 22, 2010 at 2:12 AM, Erik Iverson  wrote:
> Alex Ruiz E. wrote:
>>
>> Dear R helpers,
>>
>> I created a somewhat big database (+206,700 rows) in MySQL and have
>> exported into a csv file, but I can't open the whole thing in R. I am
>> using:
>>
>>> base<-read.csv("/path/to/file.csv", header=F, sep="," nrows=206720)
>>
>> R doesn't complain but it only opens 128,328 observations (the number of
>> columns corresponds to the original database):
>>
>>> dim(base)
>>
>> [1] 128328    134
>
> Have you verified that file.csv does indeed contain the number of rows you
> think it does? Can you go to line 128328 of the CSV file and look if it's
> any different?
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



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

What is the problem that you are trying to solve?

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


Re: [R] Getting sink to work with "message" on R 2.11.0 - what did I miss?

2010-05-22 Thread Tal Galili
Hi all,
As I wrote on other instances of this thread (that I think gotten split
because of me - my apologies for that!), I was able to use Greg Snow
solution to write something up for Faiz (and other blind R users), to help
direct R output into word.
I published it here:
http://www.r-statistics.com/2010/05/helping-the-blind-use-r-by-exporting-r-console-to-word/

I
hope it will help.

My thank for all of you who where willing to help!

With much respect,
Tal

Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Sat, May 22, 2010 at 12:32 PM, Tal Galili  wrote:

> Hello Greg,
> This is exactly what I was looking for, thank you very much for both
> writing the code and of replying here!
>
> I'll publish a small hack that uses this with R2wd shortly, in the hopes it
> will help Faiz request.
>
> Best,
> Tal
>
>
> Contact
> Details:---
> Contact me: tal.gal...@gmail.com |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
>
> --
>
>
>
>
> On Sat, May 22, 2010 at 12:34 AM, Greg Snow  wrote:
>
>> Look at txtStart and friends in the TeachingDemos package as an
>> alternative to sink that includes commands as well as output.
>>
>> --
>> 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 Tal Galili
>> > Sent: Friday, May 21, 2010 3:21 PM
>> > To: David Winsemius
>> > Cc: r-help@r-project.org
>> > Subject: Re: [R] Getting sink to work with "message" on R 2.11.0 - what
>> > did I miss?
>> >
>> > Hi David,
>> >
>> > I want to get both the 4 and the "1+3" that created it.
>> >
>> > I am trying to help someone else on the mailing list that is looking
>> > for a
>> > way to "sink" the console into word, so he could have word read it to
>> > him
>> > (he is blind).
>> > I know how to do the second part, but the first part (using sink with
>> > the
>> > commands, and not just the output), I am somehow missing...
>> >
>> > Best,
>> > Tal
>> >
>> >
>> >
>> > Contact
>> > Details:---
>> > Contact me: tal.gal...@gmail.com |  972-52-7275845
>> > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew)
>> > |
>> > www.r-statistics.com (English)
>> > ---
>> > ---
>> >
>> >
>> >
>> >
>> > On Sat, May 22, 2010 at 12:17 AM, David Winsemius
>> > wrote:
>> >
>> > >
>> > > On May 21, 2010, at 5:02 PM, Tal Galili wrote:
>> > >
>> > >  Hi all,
>> > >>
>> > >> I am trying to use type message with sink, like this:
>> > >>
>> > >> sink("all.Rout", type="message")
>> > >> 1+3
>> > >>
>> > >> sink()
>> > >>
>> > >> readLines(con = "all.Rout")
>> > >>
>> > >> So to get the following output:
>> > >>
>> > >>  1+3
>> > >>>
>> > >> [1] 4
>> > >>
>> > >> Obviously this doesn't work.
>> > >>
>> > >>
>> > > What are you trying to do? The sink help page has two rather dire
>> > warnings
>> > > about not using type="message",  and using type="output would give
>> > you what
>> > > you ask:
>> > >
>> > > > sink("all.Rout", type="output")
>> > >
>> > > > 1+3
>> > > >
>> > > > sink()
>> > > >
>> > > > readLines(con = "all.Rout")
>> > > [1] "[1] 4"
>> > >
>> > > The extra "[1]" and quotes are from the readLines function, not from
>> > > all.Rout.
>> > >
>> > >
>> > >  I tried some variations (based on the explanations in the help) but
>> > am
>> > >> missing something on how to make it work.
>> > >>
>> > >> Any suggestions?
>> > >>
>> > >> (p.s: I need this so to help Faiz Rasool in his latest post)
>> > >>
>> > >> Thanks,
>> > >>
>> > >> Tal
>> > >>
>> > > --
>> > > David Winsemius, MD
>> > > West Hartford, CT
>> > >
>> > >
>> >
>> >   [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide http://www.R-project.org/posting-
>> > guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

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

Re: [R] Capturing R console output into a file (sink+savehistory ??)

2010-05-22 Thread Tal Galili
Hello Duncan, David, and other R-help mailing list members.

I found the solution using Greg Snow answer to this thread.

I wanted to have that so to help a blind person who asked on the mailing
list how to direct R output to word.

I wrote up a solution, and wrapped it with words.  It is now published here:
http://www.r-statistics.com/2010/05/helping-the-blind-use-r-by-exporting-r-console-to-word/

Thank you for offering your help.

Best,
Tal

Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Sat, May 22, 2010 at 1:26 PM, Duncan Murdoch wrote:

> Tal Galili wrote:
>
>> After reading more, I understand I didn't formulate my last question
>> correctly, so please allow me to rephrase:
>>
>> What I am looking for is a way to save the R console session output.
>> That is, a command that would combine the results of using:
>> ?sink   # And
>> ?savehistory
>>
>>
>
> I think there's still some ambiguity in the question; I'll try to answer a
> few versions.
>
> Do you want to run R normally, then afterwards save the console log?  That
> depends on what front end you're using.  In the Windows GUI, you can do it
> with
> Ctrl-A to select everything in the console, then menu items File | Save to
> file..., or just Ctrl-C to copy, and then paste it into Word.  Similar
> operations would work on a Mac.
>
> Do you want to run code in a way that writes it to a file without
> displaying it to the screen?  R CMD batch does that.
>
> Do you want to run just a few commands like that? Then try
>
> capture.output(source(stdin(), echo=TRUE))
>
> This will accept commands from the console until it hits an EOF (Ctrl-Z on
> Windows, I don't know on other systems, but Ctrl-D is a good guess) and will
> return
> the results in a character vector, which you could write to a file.
>
> Do you want to run R normally with output on screen, but also logging
> everything to a file?  I don't know how to do that in the R GUI in Windows,
> but there are probably command line tools that could do it.
>
> Duncan Murdoch
>
>   My motivation for this is that doing it will allow someone who is a blind
>> user of R to be able to easily export his results to word so he could have
>> word read him the text.
>> I also imagine it might be useful for session login.
>>
>> Thanks,
>> Tal
>>
>>
>>
>>
>> Contact
>> Details:---
>> Contact me: tal.gal...@gmail.com |  972-52-7275845
>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>> www.r-statistics.com (English)
>>
>> --
>>
>>
>>
>>
>> On Sat, May 22, 2010 at 12:20 AM, Tal Galili 
>> wrote:
>>
>>
>>
>>> Hi David,
>>>
>>> I want to get both the 4 and the "1+3" that created it.
>>>
>>> I am trying to help someone else on the mailing list that is looking for
>>> a
>>> way to "sink" the console into word, so he could have word read it to him
>>> (he is blind).
>>> I know how to do the second part, but the first part (using sink with the
>>> commands, and not just the output), I am somehow missing...
>>>
>>> Best,
>>> Tal
>>>
>>>
>>>
>>> Contact
>>> Details:---
>>> Contact me: tal.gal...@gmail.com |  972-52-7275845
>>> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
>>> www.r-statistics.com (English)
>>>
>>>
>>> --
>>>
>>>
>>>
>>>
>>> On Sat, May 22, 2010 at 12:17 AM, David Winsemius <
>>> dwinsem...@comcast.net>wrote:
>>>
>>>
>>>
 On May 21, 2010, at 5:02 PM, Tal Galili wrote:

  Hi all,


> I am trying to use type message with sink, like this:
>
> sink("all.Rout", type="message")
> 1+3
>
> sink()
>
> readLines(con = "all.Rout")
>
> So to get the following output:
>
>  1+3
>[1] 4
>
> Obviously this doesn't work.
>
>
>
>
 What are you trying to do? The sink help page has two rather dire
 warnings
 about not using type="message",  and using type="output would give you
 what
 you ask:



> sink("all.Rout", type="output")
>1+3
>
> sink()
>
> readLines(con = "all.Rout")
>
>
 [1] "[1] 4"

 The extra "[1]" and quotes are from the readLines function, not from
 all.Rout.


  I tried some variations (based on the explanations in the help) but am


> missing something on how to make it work.
>
> Any suggestions?
>
> (p.s: I need this so to he

Re: [R] Reading results of commands in Microsoft Word typed in the terminal window, A question from a Blind R user.

2010-05-22 Thread Tal Galili
Hello Faiz,

I just wrote an extended tutorial that (I believe) fully addresses your
question, here:

http://www.r-statistics.com/2010/05/helping-the-blind-use-r-by-exporting-r-console-to-word/

(It is based on Greg Snows answer on the other thread, coupled with
the article I once wrote on some of the main features R2wd offers.  I
suggest you read it as well:
http://www.r-statistics.com/2010/05/exporting-r-output-to-ms-word-with-r2wd-an-example-session/
)

Let me know if it helps, and good luck to you!
Best,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Thu, May 20, 2010 at 12:23 PM, Faiz Rasool  wrote:

> Hi all,
>
> I would like to read the results of the commands type in the terminal
> window in Microsoft Word. As a blind user my options are somewhat limited
> and are time consuming if I want to see the results of the commands that I
> have type earlier. for example if  my first two commands were
>  x<-c(1,2,3,4,5)
> mean(x)
> and I have typed ten more commands after the first two commands it is not
> easy for me to see that what was the result of mean(x)
> but if I can somehow divert the results of the commands to Microsoft Word
> it is comparatively easy for me to see what was the result of mean(x) and
> what were the results of other commands. One another advantage of diverting
> R's output to Microsoft Word for me is that from there they can be easily
> copied into assignments as well.
>
> Any ideas and suggestions are appreciated.
>
> faiz.
>
>
>
>
>
>
>
>[[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.


[R] question about graph

2010-05-22 Thread khazaei
Hi,


I have two different sets of data from two different populations. I want
to plot these samples (for example: Line graph) by just one graph.
could you please help me?

Thanks
Khazaei

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


Re: [R] Getting sink to work with "message" on R 2.11.0 - what did I miss?

2010-05-22 Thread Tal Galili
Hello Greg,
This is exactly what I was looking for, thank you very much for both writing
the code and of replying here!

I'll publish a small hack that uses this with R2wd shortly, in the hopes it
will help Faiz request.

Best,
Tal


Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Sat, May 22, 2010 at 12:34 AM, Greg Snow  wrote:

> Look at txtStart and friends in the TeachingDemos package as an alternative
> to sink that includes commands as well as output.
>
> --
> 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 Tal Galili
> > Sent: Friday, May 21, 2010 3:21 PM
> > To: David Winsemius
> > Cc: r-help@r-project.org
> > Subject: Re: [R] Getting sink to work with "message" on R 2.11.0 - what
> > did I miss?
> >
> > Hi David,
> >
> > I want to get both the 4 and the "1+3" that created it.
> >
> > I am trying to help someone else on the mailing list that is looking
> > for a
> > way to "sink" the console into word, so he could have word read it to
> > him
> > (he is blind).
> > I know how to do the second part, but the first part (using sink with
> > the
> > commands, and not just the output), I am somehow missing...
> >
> > Best,
> > Tal
> >
> >
> >
> > Contact
> > Details:---
> > Contact me: tal.gal...@gmail.com |  972-52-7275845
> > Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew)
> > |
> > www.r-statistics.com (English)
> > ---
> > ---
> >
> >
> >
> >
> > On Sat, May 22, 2010 at 12:17 AM, David Winsemius
> > wrote:
> >
> > >
> > > On May 21, 2010, at 5:02 PM, Tal Galili wrote:
> > >
> > >  Hi all,
> > >>
> > >> I am trying to use type message with sink, like this:
> > >>
> > >> sink("all.Rout", type="message")
> > >> 1+3
> > >>
> > >> sink()
> > >>
> > >> readLines(con = "all.Rout")
> > >>
> > >> So to get the following output:
> > >>
> > >>  1+3
> > >>>
> > >> [1] 4
> > >>
> > >> Obviously this doesn't work.
> > >>
> > >>
> > > What are you trying to do? The sink help page has two rather dire
> > warnings
> > > about not using type="message",  and using type="output would give
> > you what
> > > you ask:
> > >
> > > > sink("all.Rout", type="output")
> > >
> > > > 1+3
> > > >
> > > > sink()
> > > >
> > > > readLines(con = "all.Rout")
> > > [1] "[1] 4"
> > >
> > > The extra "[1]" and quotes are from the readLines function, not from
> > > all.Rout.
> > >
> > >
> > >  I tried some variations (based on the explanations in the help) but
> > am
> > >> missing something on how to make it work.
> > >>
> > >> Any suggestions?
> > >>
> > >> (p.s: I need this so to help Faiz Rasool in his latest post)
> > >>
> > >> Thanks,
> > >>
> > >> Tal
> > >>
> > > --
> > > David Winsemius, MD
> > > West Hartford, CT
> > >
> > >
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/posting-
> > guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[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] Getting sink to work with "message" on R 2.11.0 - what didI miss?

2010-05-22 Thread Faiz Rasool

Thank you to all of those who are trying to help me.

I am using Windows XP, and using a screen reader called JAWS. When I type
something at the console, I hear once what I have typed, and then the focus
is on the next line. Then if I press the up arrow key I get to hear the
function I just typed, not its output. For example if I type mean(x) and
then I press enter I will hear "[5]" if it is the mean of x. Then I will
hear ">". Now if I want to find out what was the mean of x by pressing the
up arrow key, I will only hear mean(x) and I will not hear [5]. My screen
reader does provide options to use different cursors to read command lines.
but if I have typed median(x) sd(x) var(x) length(x) after typing mean(x),
it takes a long time before I can move my cursor to the location where I can
hear the mean of x. If the results of the commands can be diverted to MS
Word it becomes comparatively easy for me to quickly move forward and
backward in the document. Following suggestion of Gregory Snow, I will look
at emacs. I could not find the txtStart function and TeachingDemos package
after typing TxtStart() and library(TeachingDemos) I am unable to decide how
to use the code provided by David Winsemius. Should I just copy that to
console and it will start to divert the output to a txt or a .doc file?

Thank you once again to all of those who have participated in this thread.
Faiz.

- Original Message - 
From: "David Winsemius" 

To: "Greg Snow" 
Cc: 
Sent: Saturday, May 22, 2010 2:46 AM
Subject: Re: [R] Getting sink to work with "message" on R 2.11.0 - what didI
miss?




On May 21, 2010, at 5:34 PM, Greg Snow wrote:

Look at txtStart and friends in the TeachingDemos package as an 
alternative to sink that includes commands as well as output.


Know the quality of Greg Snows work it will probably be better than  mine, 
but perhaps:


> capfn <- function(inp) {
+  instring <- deparse(substitute(inp))
+  capture.output(instring, inp, file="all.Rout") }
> capfn(1+3)

The file looks like this:

[1] "1 + 3"
[1] 4


--
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 Tal Galili
Sent: Friday, May 21, 2010 3:21 PM
To: David Winsemius
Cc: r-help@r-project.org
Subject: Re: [R] Getting sink to work with "message" on R 2.11.0 -  what
did I miss?

Hi David,

I want to get both the 4 and the "1+3" that created it.

I am trying to help someone else on the mailing list that is looking
for a
way to "sink" the console into word, so he could have word read it to
him
(he is blind).
I know how to do the second part, but the first part (using sink with
the
commands, and not just the output), I am somehow missing...

Best,
Tal



Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il  (Hebrew)
|
www.r-statistics.com (English)
---
---




On Sat, May 22, 2010 at 12:17 AM, David Winsemius
wrote:



On May 21, 2010, at 5:02 PM, Tal Galili wrote:

Hi all,


I am trying to use type message with sink, like this:

sink("all.Rout", type="message")
1+3

sink()

readLines(con = "all.Rout")

So to get the following output:

1+3



[1] 4

Obviously this doesn't work.



What are you trying to do? The sink help page has two rather dire

warnings

about not using type="message",  and using type="output would give

you what

you ask:


sink("all.Rout", type="output")



1+3

sink()

readLines(con = "all.Rout")

[1] "[1] 4"

The extra "[1]" and quotes are from the readLines function, not from
all.Rout.


I tried some variations (based on the explanations in the help) but

am

missing something on how to make it work.

Any suggestions?

(p.s: I need this so to help Faiz Rasool in his latest post)

Thanks,

Tal


--
David Winsemius, MD
West Hartford, CT




[[alternative HTML version deleted]]

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


David Winsemius, MD
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.


- Original Message - 
From: "David Winsemius" 

To: "Greg Snow" 
Cc: 
Sent: Saturday, May 22, 2010 2:46 AM
Subject: Re: [R] Getting sink to work with "message" on R 2.11.0 - what didI 
miss?





On May 21, 2010, at 5:34 PM, Greg Snow wrote:

Look at t

[R] Capturing R console output into a file (sink+savehistory ??)

2010-05-22 Thread Tal Galili
After reading more, I understand I didn't formulate my last question
correctly, so please allow me to rephrase:

What I am looking for is a way to save the R console session output.
That is, a command that would combine the results of using:
?sink   # And
?savehistory

My motivation for this is that doing it will allow someone who is a blind
user of R to be able to easily export his results to word so he could have
word read him the text.
I also imagine it might be useful for session login.

Thanks,
Tal




Contact
Details:---
Contact me: tal.gal...@gmail.com |  972-52-7275845
Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
www.r-statistics.com (English)
--




On Sat, May 22, 2010 at 12:20 AM, Tal Galili  wrote:

> Hi David,
>
> I want to get both the 4 and the "1+3" that created it.
>
> I am trying to help someone else on the mailing list that is looking for a
> way to "sink" the console into word, so he could have word read it to him
> (he is blind).
> I know how to do the second part, but the first part (using sink with the
> commands, and not just the output), I am somehow missing...
>
> Best,
> Tal
>
>
>
> Contact
> Details:---
> Contact me: tal.gal...@gmail.com |  972-52-7275845
> Read me: www.talgalili.com (Hebrew) | www.biostatistics.co.il (Hebrew) |
> www.r-statistics.com (English)
>
> --
>
>
>
>
> On Sat, May 22, 2010 at 12:17 AM, David Winsemius 
> wrote:
>
>>
>> On May 21, 2010, at 5:02 PM, Tal Galili wrote:
>>
>>  Hi all,
>>>
>>> I am trying to use type message with sink, like this:
>>>
>>> sink("all.Rout", type="message")
>>> 1+3
>>>
>>> sink()
>>>
>>> readLines(con = "all.Rout")
>>>
>>> So to get the following output:
>>>
>>>  1+3

>>> [1] 4
>>>
>>> Obviously this doesn't work.
>>>
>>>
>> What are you trying to do? The sink help page has two rather dire warnings
>> about not using type="message",  and using type="output would give you what
>> you ask:
>>
>> > sink("all.Rout", type="output")
>>
>> > 1+3
>> >
>> > sink()
>> >
>> > readLines(con = "all.Rout")
>> [1] "[1] 4"
>>
>> The extra "[1]" and quotes are from the readLines function, not from
>> all.Rout.
>>
>>
>>  I tried some variations (based on the explanations in the help) but am
>>> missing something on how to make it work.
>>>
>>> Any suggestions?
>>>
>>> (p.s: I need this so to help Faiz Rasool in his latest post)
>>>
>>> Thanks,
>>>
>>> Tal
>>>
>> --
>> David Winsemius, MD
>> West Hartford, CT
>>
>>
>

[[alternative HTML version deleted]]

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