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

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

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 genera

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

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,

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

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 be

[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

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) samp

[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

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

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

[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

[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=P

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 anoth

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

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

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

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

[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

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

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: D

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"

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

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

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 grap

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

[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} \include

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

[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

[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

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: kha

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

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

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

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 doe

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

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 thi

[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

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

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

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 publi

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

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

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

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,

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