Re: [R] Smooth ecdf

2011-08-15 Thread Jorge Ivan Velez
Hi Jeff, Take a look at ?density HTH, Jorge On Mon, Aug 15, 2011 at 2:38 PM, Jeffrey Joh <> wrote: > > > Is it possible to smooth an ecdf plot and get a probability density plot? > I have about 8000 points and I was hoping to get a density curve instead of > a histogram. > > > > Jeff > _

Re: [R] how can I read a xlsx file

2011-08-15 Thread Jorge Ivan Velez
Hi Albert, Another option would be the following: install.packages('gdata') require(gdata) ?read.xlsx HTH, Jorge On Mon, Aug 15, 2011 at 11:19 AM, albert coster <> wrote: > Hello, > > How can I read a xlsx file using xlsx package? > > Thanks > > Albert > >[[alternative HTML version de

Re: [R] Not sure how to use aggregate, colSums, by

2011-08-14 Thread Jorge Ivan Velez
Hi eric, Try lapply(with(x, split(x, e2)), function(l){ r <- with(l, aggregate(list(y, f), list(e1), sum)) colnames(r) <- c('e1', 'y', 'f') r }) HTH, Jorge On Sun, Aug 14, 2011 at 1:20 PM, eric <> wrote: > I have a data frame called test shown below that i would like to summarize > in > a

Re: [R] conditional filter resulting in 2 new dataframes

2011-08-14 Thread Jorge Ivan Velez
Hi, Try ifelse(initial < 5, initial, 0) ifelse(initial >= 5, initial, 0) and take a look at ?ifelse HTH, Jorge On Sat, Aug 13, 2011 at 9:02 PM, andrewjt <> wrote: > This is what I am starting with: > > initial<- matrix(c(1,5,4,8,4,4,8,6,4,2,7,5,4,5,3,2,4,6), nrow=6, > ncol=3,dimnames=list(c(

Re: [R] How do I subset a dataframe

2011-08-14 Thread Jorge Ivan Velez
Hi eric, See R> ?"%in%" and try the following (untested): subset(zeespan, !customer %in% c("ibm" , "exxon" , "sears") ) HTH, Jorge On Sat, Aug 13, 2011 at 7:44 PM, eric <> wrote: > I have a dataframe zeespan. One of the columns has the name "customer". The > data in the customer column is

Re: [R] Correlation Matrix - p value?

2011-08-09 Thread Jorge Ivan Velez
?cor.test cor.test(x, y, method = "spearman")$p.value HTH, Jorge On Tue, Aug 9, 2011 at 8:44 AM, ScottM <> wrote: > Hello all, > > I've run a Spearman's Rank test to discern relationships between landscape > characteristics and a specific aspect of river behaviour. > > I've executed a correlati

Re: [R] Printing data frame with million rows

2011-08-07 Thread Jorge Ivan Velez
?write.table HTH, Jorge On Sun, Aug 7, 2011 at 2:08 PM, Bansal, Vikas <> wrote: > Dear all, > > I was working on number of files and at the end I got a data frame with > approx. million rows.To prin this data frame in output, I used > > capture.output(print.data.frame(end,row.names=F), file = "

Re: [R] Gamma distribution parameter estimation

2011-08-06 Thread Jorge Ivan Velez
Hi Alex, Try > require(MASS) Loading required package: MASS > b <- c(2039L, 2088L, 5966L, 2353L, 1966L, 2312L, 3305L, 2013L, 3376L, + 3363L, 3567L, 4798L, 2032L, 1699L, 3001L, 2329L, 3944L, 2568L, + 1699L, 4545L) > fitdistr(b, 'gamma') shape rate 6.4528939045 0.0021887943 (0.

Re: [R] summing columns with NAs present

2011-08-05 Thread Jorge Ivan Velez
Try test$Sum <- rowSums(test, na.rm = TRUE) test HTH, Jorge On Fri, Aug 5, 2011 at 2:01 PM, Dimitri Liakhovitski <> wrote: > Hello! > > I have a data frame with some NAs. > test<-data.frame(a=c(1,2,NA),b=c(10,NA,20)) > > I need to sum up values in 2 variables. However: > test$a+test$b > procud

Re: [R] SNP Tables

2011-07-26 Thread Jorge Ivan Velez
Hi Jim, Here is one way: # data x <- structure(list(category = structure(c(1L, 1L, 1L, 2L, 2L, 2L, 1L, 1L, 2L), .Label = c("case", "control"), class = "factor"), SNP1 = c(1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L), SNP2 = c(0L, 1L, 2L, 1L, 2L, 0L, 0L, 1L, 0L), SNP3 = c(2L, 1L, 2L, 0L, 1L, 0L

Re: [R] Deleting rows and store the deleted rows in new data frame

2011-07-24 Thread Jorge Ivan Velez
Or just subset(df, V5 >= 10) See ?subset. HTH, Jorge On Sun, Jul 24, 2011 at 10:01 PM, Bansal, Vikas <> wrote: > Dear Jeff, > > Thanks a lot for your reply. > I was just curious about this thing about grep that it can perform this > kind of thing or not. Otherwise with numerical comparison I

Re: [R] Saving fExtremes estimates and k-block return level with confidence intervals.

2011-06-30 Thread Jorge Ivan Velez
Hi Peter, Try data.frame(n = names(res2), t(sapply(res2, function(l) l@fit$par.ests))) for the first part. HTH, Jorge On Thu, Jun 30, 2011 at 12:16 AM, Peter Maclean <> wrote: > I am estimating a large model by groups. How do you save the results > and returns > the associated quantiles? >

Re: [R] DROP OBSEVATION IN A GROUP

2011-06-30 Thread Jorge Ivan Velez
Hi Peter, Try this: r <- with(z, tapply(y, n, function(x) sum(x == 0) > 2)) z[!rep(r, with(z, table(n))), ] HTH, Jorge On Thu, Jun 30, 2011 at 1:05 AM, Peter Maclean <> wrote: > I tried this but did not work: > z0<- by(z, z[,"n"], function(x) subset(x, sum(n==0)>2)) > Peter Maclean > Departm

Re: [R] 2d rndom walk

2011-06-29 Thread Jorge Ivan Velez
Hi Komal, Try this: walk2d<-function(n){ rw <- matrix(0, ncol = 2, nrow = n) # generate the indices to set the deltas indx <- cbind(seq(n), sample(c(1, 2), n, TRUE)) # now set the values rw[indx] <- sample(c(-1, 1), n, TRUE) # cumsum the columns rw[,1] <- cumsum(rw[, 1]) rw[,2] <- cumsum(rw[, 2

Re: [R] Simple simulations

2011-06-27 Thread Jorge Ivan Velez
Hi robcinm, You might also consider: # data x <- c(rep(0, 20), 1:37) # number of simulations B <- 1000 # result: TRUE/FALSE out <- replicate(B, { y <- sample(x, 3, replace = FALSE) all(y == 0) }) mean(out) HTH, Jorge On Mon, Jun 27, 2011 at 5:08 PM, robcinm <> wrote: > I

Re: [R] Fw:

2011-06-26 Thread Jorge Ivan Velez
Hi Ungku, Check ?persp ?volcano in the R console. HTH, Jorge On Sun, Jun 26, 2011 at 9:22 PM, Ungku Akashah <> wrote: > > > > - Forwarded Message - > From: Ungku Akashah <> > To: "r-help@r-project.org" <> > Sent: Friday, June 24, 2011 3:15 PM > Subject: > > > hello. > I need some hel

Re: [R] i want to unsubscribe

2011-06-25 Thread Jorge Ivan Velez
Check "R-help Subscribers" at https://stat.ethz.ch/mailman/listinfo/r-help HTH, Jorge On Sun, Jun 26, 2011 at 2:17 AM, elisheva corn <> wrote: > how do i unsubscribe > >[[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing

Re: [R] ddply to count frequency of combinations

2011-06-21 Thread Jorge Ivan Velez
Hi Idris, I do not know what the correct use of ddply would be, but here is another option using paste() and table(); data.frame(with(df, table(paste("(", x, ",", y, ")", sep = "" HTH, Jorge On Tue, Jun 21, 2011 at 2:30 PM, Idris Raja <> wrote: > I have a dataframe df with two columns x a

Re: [R] omitting columns from a data frame

2011-06-20 Thread Jorge Ivan Velez
Hi Erin, One option woild be subset(), especially the "select" parameter. HTH, Jorge On Mon, Jun 20, 2011 at 11:45 PM, Erin Hodgess <> wrote: > Dear R People: > > I have a data frame, xm1, which has 12 rows and 4 columns. > > If I put is xm1[,-4], I get all rows, and columns 1 - 3, which is as

Re: [R] Linear model - coefficients

2011-06-12 Thread Jorge Ivan Velez
Hi Robert, Try this: reg2 <- lm( Y ~ factor(x1) + factor(x2) + factor(x3) + factor(x4) + factor(x5) - 1, data = X ) cof(ref2) HTH, Jorge On Sun, Jun 12, 2011 at 4:40 PM, Robert Ruser <> wrote: > Prof. Ripley, thank you very much for the answer but wanted to get > something else. There is an

Re: [R] Likelihood ratio test

2011-06-12 Thread Jorge Ivan Velez
Hi Diviya, Take a look at the lrtest function in the lmtest package: install.packages('lmtest) require(lmtest) ?lrtest HTH, Jorge On Sun, Jun 12, 2011 at 1:16 PM, Diviya Smith <> wrote: > Hello there, > > I want to perform a likelihood ratio test to check if a single exponential > or a sum of

Re: [R] Counting the Number of Letters in a row

2011-06-10 Thread Jorge Ivan Velez
Hi Abraham, Try foo <- function(x){ x <- as.character(x) sapply(strsplit(x, " "), function(s) sum(nchar(s))) } foo(f1$keyword) HTH, Jorge On Fri, Jun 10, 2011 at 12:48 PM, Abraham Mathew <> wrote: > I'm trying to find the total number of letters in a row of a data frame. > > Let's say I have

Re: [R] How to subset based on column name that is a number ?

2011-06-09 Thread Jorge Ivan Velez
Hi Mauricio, Try the following: # using the iris data require(MASS) x <- iris x[x[, 5] == 'setosa',] # and your data dframe[dframe[, 1] == "FY11_Q4", ] HTH, Jorge On Thu, Jun 9, 2011 at 3:34 PM, Mauricio Cornejo <> wrote: > Hi, > > I have a data frame with column names "1", "2", "3", ... and

Re: [R] Problem in R documentation

2011-06-06 Thread Jorge Ivan Velez
Hi Siddharth, adf.test() is part of the "tseries" package, so you need to download and install it before using that function. Try the following and let us now what you get: install.packages('tseries') require(tseries) ?adf.test HTH, Jorge On Mon, Jun 6, 2011 at 2:41 AM, siddharth arun <> wrote

Re: [R] How to convert a factor column into a numeric one?

2011-06-04 Thread Jorge Ivan Velez
Dr. LaBudde, Perhaps as.numeric(as.character(x)) is what you are looking for. HTH, Jorge On Sun, Jun 5, 2011 at 12:31 AM, Robert A. LaBudde <> wrote: > I have a data frame: > > > head(df) > Time Temp Conc ReplLog10 > 10 -20H1 6.406547 > 22 -20H1 5.738683 > 3

Re: [R] Transforming a data matrix into a vector

2011-05-30 Thread Jorge Ivan Velez
Hi Charles, Try rep(c(tmp), each = 3) HTH, Jorge On Mon, May 30, 2011 at 4:22 PM, Charles Ellis <> wrote: > Hi, > > I am trying to transform a data matrix into a vector and have not be able > to accomplish want I am looking for. The setup is as follows. I start with > a 3 x 3 matrix: > > 5 1

Re: [R] Simulation from discrete uniform

2011-05-29 Thread Jorge Ivan Velez
Hi Serdar, Take a look at the following: > sample(0:9, 100, replace = FALSE) Error in sample(0:9, 100, replace = FALSE) : cannot take a sample larger than the population when 'replace = FALSE' > sample(0:9, 100, replace = TRUE) [1] 5 6 5 7 3 0 8 4 8 2 2 4 7 6 0 7 0 0 0 7 5 6 3 6 0 9 6 1 2 6 9

Re: [R] how to compute the inverse percentile of a given observation w.r.t. a reference distribution

2011-05-25 Thread Jorge Ivan Velez
Hi Rudi, Take a look at ?ecdf HTH, Jorge On Wed, May 25, 2011 at 3:42 PM, rudi <> wrote: > Hi, > > can anyone help me to figure out how to compute the percentile of an > individual observation with respect to a reference distribution. > > What I mean is. Let's assume I have a vector consisting

Re: [R] convert binary vector to time series of sum(x)/minute

2011-05-21 Thread Jorge Ivan Velez
Hi mac, Try N <- 6000 x <- sample(1:0, N, TRUE) tapply(x, rep(1:(N/60), each = 60), sum) HTH, Jorge On Sat, May 21, 2011 at 1:59 PM, andyjmac <> wrote: > Dear members, > > I apologize for the relatively simple request, but I couldn't find exactly > what I was looking for. I have a binary vect

Re: [R] Adding a numeric to all values in the dataframe

2011-05-19 Thread Jorge Ivan Velez
Hi, Does the following work for you? set.seed(123) d <- data.frame(x = rpois(10, 4), y = rnorm(10)) d d + 2 See ?within for one more option. HTH, Jorge On Thu, May 19, 2011 at 11:54 PM, Ramya <> wrote: > Hi there > > I just want to add 2 to all the values in dataframe. > > I tried using sapp

Re: [R] Separating boot results

2011-05-19 Thread Jorge Ivan Velez
>> - that gives me subscript out of bounds error. perhaps I can tweak the >> parameters? I've never worked with that command. >> >> Pat >> >> On Thu, May 19, 2011 at 2:12 PM, Jorge Ivan Velez <> wrote: >> >>> Hi Patrick, >>>

Re: [R] How to get rid of the index in result file

2011-05-19 Thread Jorge Ivan Velez
Hi Yighua, Try > m <- 2.35343 > m [1] 2.35343 > cat(m) 2.35343 HTH, Jorge On Thu, May 19, 2011 at 2:35 PM, Hu, Yinghua <> wrote: > Hi, > > I am running some function in Ubuntu command line and get some problem. I > used some command like below > > $ R --slave -vanilla < my_infile > my_outfile

Re: [R] Separating boot results

2011-05-19 Thread Jorge Ivan Velez
Hi Patrick, How about this (untested)? a <- codboot[c(4)] round(a$bca[4, 5], 2) HTH, Jorge On Thu, May 19, 2011 at 7:20 AM, Patrick Santoso <> wrote: > Good Morning, > > I'm having what I hope to be a simple problem. I am generating bootstrap > confidence intervals using package (boot) - whic

Re: [R] Finding row in matrix with minimum column

2011-05-18 Thread Jorge Ivan Velez
Hi Worik, See ?which.min x <- matrix(c(7, 7, 9, 7, 7, 9, 2, 9), ncol = 2, byrow = FALSE) which.min(x[,2]) x[which.min(x[,2]), ] HTH, Jorge On Wed, May 18, 2011 at 10:38 PM, Worik R <> wrote: > Friends > > If I have a matrix such as... > > [,1] [,2] > [1,]77 > [2,]79 > [3,]

Re: [R] subsetting a list of dataframes

2011-05-17 Thread Jorge Ivan Velez
Hi Lara, You might try the following (untested): yourlistofdataframes[sapply(yourlistofdataframes, function(d) nrow(d) > 1)] HTH, Jorge On Tue, May 17, 2011 at 4:24 PM, Lara Poplarski <> wrote: > Hello All, > > I have a list of dataframes, and I need to subset it by keeping only those > dataf

Re: [R] Simulating correlations with varying sample sizes

2011-05-16 Thread Jorge Ivan Velez
Hi Holger, Replace "N" by "N[i]". HTH, Jorge On Mon, May 16, 2011 at 9:42 AM, Holger Steinmetz <> wrote: > Hi there, > > I would like to draw 10 correlations from a bivariate population - but > every > draw should be done with a different sample size. I thought I could to this > with a loop: >

Re: [R] Quick question: Omitting rows and cols with certain percents of missing values

2011-05-13 Thread Jorge Ivan Velez
Hi Vickie, You might try the following: # some data set.seed(123) X <- matrix(rnorm(1000), ncol = 20) X[sample(1000, 100)] <- NA # excluding rows with NA >20% X[!rowMeans(is.na(X)) > 0.2, ] # excluding columns with NA >10% X[, !colMeans(is.na(X)) > 0.1] See ?is.na, ?rowMeans and ?colMeans for

Re: [R] Generating a best fit line for non linear data

2011-04-28 Thread Jorge Ivan Velez
Hi, Try > d <- data.frame(samples, species) > fit = nls(species ~ a *(1 - exp(-b*samples)), start = list(a = 27, b = .15), data = d) > summary(fit) Formula: species ~ a * (1 - exp(-b * samples)) Parameters: Estimate Std. Error t value Pr(>|t|) a 35.824723.02073 11.860 6.10e-10 *** b 0.0

Re: [R] MASS fitdistr with plyr or data.table?

2011-04-27 Thread Jorge Ivan Velez
Hi Justin, One way of doing it is using a combination of tapply() and sapply() as follows: # data set.seed(144) weib.dist<-rweibull(1,shape=3,scale=8) weib.test.too<-data.frame(cbind(1:10,weib.dist)) names(weib.test.too)<-c('site','wind_speed') # results require(MASS) out <- with(weib.test.t

Re: [R] Question on list object

2011-04-27 Thread Jorge Ivan Velez
Hi Christofer, You might try sapply(listObj, function(l) l[1:max(sapply(listObj, length))] ) HTH, Jorge On Wed, Apr 27, 2011 at 1:23 PM, Bogaso Christofer <> wrote: > Dear all, let say, I have following list object: > > > > listObj <- vector("list", length = 3) > > listObj[[1]] <- rnorm(3) >

Re: [R] Normality tests

2011-04-26 Thread Jorge Ivan Velez
Hi Bruce, One way is via apply() # some data set.seed(123) X <- matrix(rnorm(100), ncol = 5) X # tests t(apply(X, 2, function(x){ sw <- shapiro.test(x) c(sw$statistic, P = sw$p.value) })) See ?apply and ?str and ?shapiro.test for more information. HTH, Jorge

Re: [R] Tell the difference between characters

2011-04-26 Thread Jorge Ivan Velez
Hi Lisa, Is this what you have in mind? > temp <- c("aa", "aA", "ab") > temp == temp[1] [1] TRUE FALSE FALSE HTH, Jorge On Tue, Apr 26, 2011 at 2:09 PM, Lisa <> wrote: > Dear all, > > I just want to determine if the characters in a character string are the > same or not. For example, > > tem

Re: [R] Problem having tick marks aligned when plotting three graphs on top of one another.

2011-04-22 Thread Jorge Ivan Velez
Hi Dr. Sorkin, One way of doing what you want is via matplot(): with(d, matplot(Slope, d[, -1], type = 'l', lty = 1)) where "d" is your data. HTH, Jorge On Fri, Apr 22, 2011 at 11:55 PM, John Sorkin <> wrote: > R 2.10 > Windows 7 > > I am trying to plot three graphs on top of each other. I n

Re: [R] indexing list elements with lapply?

2011-04-22 Thread Jorge Ivan Velez
Dear Simon, Try any of the following: sapply(r, function(l) l[,2] / l[1, 2]) lapply(r, function(l) l[,2] / l[1, 2]) HTH, Jorge On Fri, Apr 22, 2011 at 5:52 PM, Simon Kiss <> wrote: > Dear colleagues, > I have a list that looks like what the code below produces. I need a > function to go thr

Re: [R] all combinations with replacement

2011-04-21 Thread Jorge Ivan Velez
Hi Kehl, How large are n and k in your case? Using Dimitris' approach and I got the following timings for 1000 replicates: # function based on Dimitri's reply foo <- function(n, k){ r <- expand.grid(rep(list(0:n), k)) subset(r, rowSums(r) == n) } # a second try foo2 <- function(n

Re: [R] line type lty

2011-04-21 Thread Jorge Ivan Velez
See ?par Best, Jorge On Thu, Apr 21, 2011 at 12:22 PM, Hui Du <> wrote: > Hi All, > > >Does somebody know how to know the detail of the line types? > For example, lty = 1, means what kind of line?, lty = 2, means what kind of > line? > > >Thanks. > > HXD > >

Re: [R] Find characters in a matrix and return a TRUE-FALSE vector

2011-04-13 Thread Jorge Ivan Velez
Hi Nina, You might try sapply(yourdata, function(x) any(x == "C")) See ?sapply for more details. HTH, Jorge On Wed, Apr 13, 2011 at 7:17 AM, Vitrifizierung <> wrote: > I have the following problem: > > My data is a matrix of multiple columns and rows. The column I am > interested > in looks

Re: [R] Dump the "source code" of data frame

2011-04-13 Thread Jorge Ivan Velez
Hi CH, Take a look at ?dput HTH, Jorge On Wed, Apr 13, 2011 at 3:09 AM, C.H. <> wrote: > Dear R experts, > > I remember a similar function existed and have been mentioned in > R-help before. I tried my best to search but I really can't find it > out. > > suppose I have an data frame like this

Re: [R] list to data frame

2011-04-10 Thread Jorge Ivan Velez
Hi Franklin, Try do.call(rbind, ineffFilesList) See ?do.call for more details. HTH, Jorge On Sun, Apr 10, 2011 at 2:01 PM, Franklin Tamborello II <> wrote: > I need to make a data frame out of the data that I currently have in a > list. This works, but is ugly: > ineffData<-rbind(ineffFilesL

Re: [R] Getting number of students with zeroes in long format

2011-04-08 Thread Jorge Ivan Velez
st command they should be false > for the second command right? > > > tail(names(r[ r == TRUE ])) > [1] "999752" "999767" "999806" "999807" "999881" "999896" > > tail(names(r[ r == FALSE ])) > [1] "999869"

Re: [R] Correlation Matrix

2011-04-07 Thread Jorge Ivan Velez
I am sorry for the noise, but with(MyDataFrame[, 1:3]) should have been with(cor(MyDataFrame[, 1:3])) Best, Jorge On Thu, Apr 7, 2011 at 3:21 PM, Jorge Ivan Velez <> wrote: > Hi Dmitry, > > You might try > > with(MyDataFrame[, 1:3]) > > is variable1, variable2

Re: [R] Correlation Matrix

2011-04-07 Thread Jorge Ivan Velez
Hi Dmitry, You might try with(MyDataFrame[, 1:3]) is variable1, variable2 and variable3 correspond to the first three columns of your data, or with( MyDataFrame( cor( cbind( variable1, variable2, variable3) ) ) ) otherwise. HTH, Jorge On Thu, Apr 7, 2011 at 3:09 PM, Dmitry Berman <> wrote:

Re: [R] Selecting data from list object

2011-04-06 Thread Jorge Ivan Velez
Hi Santosh, One way would be > sapply(d, "[", 1) [1] "20110405" "20110405" "20110405" "20110405" "20110405" "20110405" HTH, Jorge On Thu, Apr 7, 2011 at 2:14 AM, santosh <> wrote: > Hello Group, > > Is there a simpler way to get data out of a list object? (like in data > frame without using t

Re: [R] force output dimension of table function

2011-04-06 Thread Jorge Ivan Velez
Hi, You might try > table(factor(s, levels = 0:5)) 0 1 2 3 4 5 0 1 1 1 0 2 HTH, Jorge On Wed, Apr 6, 2011 at 11:37 PM, fisken <> wrote: > I have a small annoying problem. > > When I use the 'table' function on a simple vector it counts the > number of occurences. > So depending on the values

Re: [R] Getting number of students with zeroes in long format

2011-04-06 Thread Jorge Ivan Velez
Hi Chris, Is this what you have in mind? > sum(with(yourdata, tapply(sus, id_r, function(x) any(x==0 [1] 13 HTH, Jorge On Wed, Apr 6, 2011 at 4:44 PM, Christopher Desjardins <> wrote: > Hi, > I have longitudinal school suspension data on students. I would like to > figure out how many stu

Re: [R] round number

2011-03-26 Thread Jorge Ivan Velez
Hi Alfredo, Try noquote(sprintf("%.2f", a*.2)) HTH, Jorge On Sat, Mar 26, 2011 at 2:05 PM, Alfredo Alessandrini <> wrote: > Hi, > > > a <- 4 > > > a*0.2 > [1] 0.8 > > ok!! > > Is there a method to obtain this: > > > a*0.2 > [1] 0.80 > > I need to round the number also with the zero. > > > > T

Re: [R] "for" loop assistance -

2011-03-25 Thread Jorge Ivan Velez
Hi Steven, One would be with(yourdataset, aggregate(x, list(lc1, id), mean)) Group.1 Group.2x 1 85 ga1 45.47261 2 95 ga1 53.38831 3 105 ga1 58.18282 4 115 ga1 63.77469 5 125 ga1 66.98222 6 85 ga2 47.55711 7 95 ga2 54.78450

Re: [R] error in bargraph.CI {sciplot}

2011-03-24 Thread Jorge Ivan Velez
Hi Barbara, Works just fine for me: > require(sciplot) Loading required package: sciplot > data(ToothGrowth) # Two-way design with options bargraph.CI(dose, len, group = supp, data = ToothGrowth, xlab = "Dose", ylab = "Growth", cex.lab = 1.5, x.leg = 1, col = "black", angle

Re: [R] tapply with specific quantile value

2011-03-24 Thread Jorge Ivan Velez
Hi Steven, See the prob argument under ?quantile. The following should be what you want: tapply(x, l.c.1, quantile, prob = 0.75) HTH, Jorge * * On Thu, Mar 24, 2011 at 7:18 PM, Steven Ranney <> wrote: > All - > > I have an example data frame > > x l.c.1 > 43.38812035 085 > 47.5571

Re: [R] How create vector that sums correct responses for multiple subjects?

2011-03-24 Thread Jorge Ivan Velez
Hi Kevin, Try this (untested): sapply(split(pretestdata, Subject), function(l) with(l$Correct == "C")) HTH, Jorge On Thu, Mar 24, 2011 at 3:24 PM, Kevin Burnham <> wrote: > I have a data file with indicates pretest scores for a linguistics > experiment. The data are in long form so for each

Re: [R] apply mean to a three-dimension data

2011-03-24 Thread Jorge Ivan Velez
Hi Hui, Ssee ?Reduce for more details. You might try something along the lines of > mymean <- function(x) Reduce("+", x)/length(x) > add(b) [,1] [,2] [1,] 10.3 12.3 [2,] 11.3 13.3 HTH, Jorge On Thu, Mar 24, 2011 at 11:07 AM, Hui Du <> wrote: > Hi All, > >

Re: [R] apply mean to a three-dimension data

2011-03-24 Thread Jorge Ivan Velez
Sorry, the above should have been > mymean <- function(x) Reduce("+", x)/length(x) > mymean(b) [,1] [,2] [1,] 10.3 12.3 [2,] 11.3 13.3 Apologies for the noise. Best, Jorge On Thu, Mar 24, 2011 at 3:54 PM, Jorge Ivan Velez <> wrote: >

Re: [R] Urgent query about R!

2011-03-22 Thread Jorge Ivan Velez
Hi Rachel, You might also try apply(expand.grid(rep(list(1:6), 4)), 1, paste, collapse = "", sep = "") HTH, Jorge * * On Tue, Mar 22, 2011 at 6:41 PM, Rachel Chu <> wrote: > Hi there, > > I am currently working on a R programming project and got stuck. > I am supposed to generate a set of pos

Re: [R] Replacing Period in String

2011-03-20 Thread Jorge Ivan Velez
Hi John, Try gsub("[.]","",txt) See "Extended Regular Expressions" in ?regex. HTH, Jorge * * On Mon, Mar 21, 2011 at 12:49 AM, Sparks, John James <> wrote: > Dear R Users, > > I am working with gsub for the first time. I am trying to remove some > characters from a string. I have hit the p

Re: [R] Output a table formatted with standard deviations below means

2011-03-19 Thread Jorge Ivan Velez
Hi Nathan, Do not know a direct way, but the following seems to work: # data means <- matrix(1:10,nrow=2) sds <- matrix(seq(0.1,1,by=0.1),nrow=2) colnames(means) <- colnames(sds) <- c("a","b","c","d","e") # adding "( )" to the SDs sdsn <- t(apply(sds, 1, function(x) paste('(', x, ')', sep = ""))

Re: [R] Differences per group

2011-03-09 Thread Jorge Ivan Velez
Hi Rens, One way would be x$difference <- do.call(c, with(x, tapply(amount, customer, function(x) c(0, diff(x) x Take a look at ?tapply and ?aggregate for more information. HTH, Jorge On Wed, Mar 9, 2011 at 10:27 AM, rens_1112 <> wrote: > Dear all, > > Probably a rather stupid question,

Re: [R] Loop Through Columns to Remove Rows

2011-03-09 Thread Jorge Ivan Velez
Hi Sam, How about this? test[apply(test, 1, function(x) !any(x == '#DIV/0!')), ] HTH, Jorge On Wed, Mar 9, 2011 at 3:29 PM, Sam Albers <> wrote: > Hello Venerable List, > > I am trying to loop (I think) an operation through a list of columns in a > dataframe to remove set of #DIV/0! values. I

Re: [R] Multiple testing corrections on very large vector

2011-03-09 Thread Jorge Ivan Velez
Hi terdon, Very happy to help and know it worked. Honestly, I do not know exactly where the differences are, but it is not hard to check the sources and compare both algorithms. When doing this, you can can see that p.adjust() uses vectorization whereas mt.rawp2adjp() does not. Perhaps that is th

Re: [R] Multiple testing corrections on very large vector

2011-03-08 Thread Jorge Ivan Velez
Hi terdon, You are absolutely right. I apologize for any inconvenience my lack of coffee might have caused :-) I simulated some p-values with the length of your vector and ran the p.adjust() function on them. Here is what I got: system.time(res <- p.adjust(pv, method = 'fdr')) user system el

Re: [R] Multiple testing corrections on very large vector

2011-03-08 Thread Jorge Ivan Velez
Hi terdon, Take a look at ?p.adjust and its argument n. For example, you could adjust B pv values by using p.adjust(pv[1:B], method = 'BH', n = B) Then, you can continue processing other subsets of pv and concatenate the result. Here, a for() loop might be useful. HTH, Jorge On Tue, Mar 8,

Re: [R] Sorting

2011-03-07 Thread Jorge Ivan Velez
Hi Whitney, If I understood correctly, what you actually want is to construct a 2x2 table considering "smoking" and "retlevel". Perhaps something along the lines of with(yourdata, table(retlevel, smoking)) could give you some insights. See ?table for more details. HTH, Jorge On Mon, Mar 7, 2

Re: [R] MCMC_glm models

2011-03-07 Thread Jorge Ivan Velez
Hi Nick, The following would be one way of doing what you want: # function to estimate one model foo <- function(mu = 9.244655, n = 50){ X <- rpois(n, mu) glm(X ~ Y, family = poisson) # note I am using family = poisson } B <- 1000 # number of samples -- change accordingly Y <- 19

Re: [R] How to reference a package in academical paper

2011-03-07 Thread Jorge Ivan Velez
Hi Jan, R> citation('RODBC') To cite package ‘RODBC’ in publications use: Brian Ripley and and from 1999 to Oct 2002 Michael Lapsley (2010). RODBC: ODBC Database Access. R package version 1.3-2. http://CRAN.R-project.org/package=RODBC A BibTeX entry for LaTeX users is @Manual{, titl

Re: [R] displaying label meeting condition (i.e. significant, i..e p value less than 005) in plot function

2011-03-05 Thread Jorge Ivan Velez
Hi Umesh, You can try something along the lines of: d <- dataf[dataf$p < 0.05, ] # p < 0.05 with(d, plot(xvar, p, col = 'white')) with(d, text(xvar, p, name, cex = .7)) HTH, Jorge On Sat, Mar 5, 2011 at 12:29 PM, Umesh Rosyara <> wrote: > Dear R users, > > Here is my problem: > > # example

Re: [R] testing power of correlation

2011-03-05 Thread Jorge Ivan Velez
Hi Anna, Take a look at ?cor ?cor.test and http://www.statmethods.net/stats/power.html HTH, Jorge On Sat, Mar 5, 2011 at 3:02 PM, Anna Gretschel <> wrote: > Dear List, > > does anyone know how I can test the strength of a correlation? > > Cheers, Anna > >

Re: [R] Grouping data in ranges in table

2011-03-05 Thread Jorge Ivan Velez
Hi Jason, Something along the lines of with(Orange, table(cut(age, breaks = c(118, 664, 1004, 1372, 1582, Inf)), cut(circumference, breaks = c(30, 58, 62, 115, 145, 179, 214 should get you started. HTH, Jorge On Sat, Mar 5, 2011 at 5:38 PM, Jason Rupert <> wrote

Re: [R] Entering table with multiple columns & rows

2011-02-28 Thread Jorge Ivan Velez
Hi Laura, May be yo meant: diet <- matrix(c(24,134,9,52,23,72,12,15), ncol = 2, byrow = TRUE) # note ncol = 2 rownames(diet) <- c("none", "healthy", "unhealthy", "dangerous") colnames(diet) <- c('Yes', 'No') diet HTH, Jorge On Mon, Feb 28, 2011 at 9:17 PM, Laura Clasemann <> wrote: > > Hi, >

Re: [R] substract 2 data.frames

2011-02-27 Thread Jorge Ivan Velez
Hi Nicolas, Try popn[!rownames(popn) %in% rownames(fish), ] HTH, Jorge On Sun, Feb 27, 2011 at 3:29 PM, Nicolas Gutierrez <> wrote: > Hi! > > I have 2 data.frames: "fish" and "popn": > > >fish > > xloc yloc id birth size weight energy gonad > 20 15 15 54 -60 107.9 63.0 15952.9 8

Re: [R] R in different OS

2011-02-25 Thread Jorge Ivan Velez
Hi Hui, May be sessionInfo() is what you are looking for. See ?sessionInfo as well as ?version for more details. You can run the following on your R session and see what comes up: sessionInfo() sessionInfo()$R.version$platform version$platform Then, you might use ifelse() to set up the right pat

Re: [R] identify an element in a column

2011-02-22 Thread Jorge Ivan Velez
Hi Gary, Try transform(z, y = ifelse(x == 5, y-1, y)) HTH, Jorge On Tue, Feb 22, 2011 at 12:18 PM, Hongwei Dong <> wrote: > Hi, R users, > > I'm wondering if I can identify an element in a column by an element in > another column. For example: > > x<-1:10 > y<-11:20 > z<-cbind(x,y) > z > x

Re: [R] concatenate vector after strsplit()

2011-02-20 Thread Jorge Ivan Velez
Hi Robert, You might try do.call(rbind, lapply(yourlist, "[", 1:4)) and then write the resulting file using write.table(...). Best, Jorge On Sun, Feb 20, 2011 at 11:13 AM, Robert Baer <> wrote: > ls is a list of character vectors created by strsplit() > > I want to concatenate the 1st 4 char

Re: [R] Generating uniformly distributed correlated data.

2011-02-19 Thread Jorge Ivan Velez
Hi Soren, Take a look at http://tolstoy.newcastle.edu.au/R/help/05/07/7741.html HTH, Jorge On Sat, Feb 19, 2011 at 9:17 PM, Søren Faurby <> wrote: > I wish to generate a vector of uniformly distributed data with a defined > correlation to another vector > > The only function I have been able

Re: [R] questions about counting numbers

2011-02-06 Thread Jorge Ivan Velez
Hi Carrie, Try > x <- rle(a) > rep(x$lengths, x$lengths) [1] 1 2 2 1 HTH, Jorge On Sun, Feb 6, 2011 at 8:21 PM, Carrie Li <> wrote: > Hello R-helpers, > > I have a question about counting numbers. > Here is a simple example. > > a=c(2, 3, 3,4) > > table(a) > a > 2 3 4 > 1 2 1 > > so, I can to

Re: [R] sum the values in a vector as a complete number

2011-01-31 Thread Jorge Ivan Velez
Hi AD, You might try the following: # data a <- c(2,3,5) b <- c(8,7) # you got this wrong ;) # option 1 foo <- function(x) as.numeric(paste(x, sep = "", collapse = "")) # examples foo(a) # [1] 235 foo(b) # [1] 87 foo(a) + foo(b) # [1] 322 # option 2 foo2 <- function(x, y) foo(x) + foo(y) #

Re: [R] data frame column name change

2011-01-16 Thread Jorge Ivan Velez
Hi eric, Try colnames(x) colnames(x)[1] <- 'newname' colnames(x) HTH, Jorge On Sun, Jan 16, 2011 at 11:28 PM, eric <> wrote: > > How do I change the name of one column in a data frame ? Suppose I have a > data frame x with 5 columns. If the names were date, col1, col2, col3, col4 > and I want

Re: [R] standard errors in johansen test

2011-01-12 Thread Jorge Ivan Velez
Hi Walter, The paper can be found at http://cran.r-project.org/web/packages/vars/vignettes/vars.pdf It seems that you need the "vars" library before trying the function you mention. What happens if you do the following? install.packages("vars") require(vars) ?cajorls ?ca.jo HTH, Jorge On Wed

Re: [R] weighed mean of a data frame row-by-row

2011-01-06 Thread Jorge Ivan Velez
Hi Vassilis, Try test.df$y <- with(test.df, x1*w + x2*(1-w)) test.df HTH, Jorge On Thu, Jan 6, 2011 at 8:33 AM, Vassilis <> wrote: > > Dear list, > > This must be an easy one. I have a data frame like this one: > > test.df <- data.frame(x1=c(2,3,5), x2=c(5, 3, 4), w=c(0.8, 0.3, 0.5)) > > and

Re: [R] Plotting colour-coded points

2011-01-05 Thread Jorge Ivan Velez
Hi Anjan, Try something along the lines of d$bb <- with(d, cut(b, c(0,9,19,29))) with(d, plot(a, id, col = bb, pch = 16, las = 1)) legend('topright', as.character(levels(d$bb)), col = 1:length(levels(d$bb)), ncol = 3, pch = 16) where 'd' is your original data.frame. HTH, Jorge On Wed, Jan 5,

Re: [R] How to 'explode' a matrix

2011-01-05 Thread Jorge Ivan Velez
Hi Kevin, Take a look at ?kronecker HTH, Jorge On Wed, Jan 5, 2011 at 7:03 AM, Kevin Ummel <> wrote: > Hi everyone, > > I'm looking for a way to 'explode' a matrix like this: > > > matrix(1:4,2,2) > [,1] [,2] > [1,]13 > [2,]24 > > into a matrix like this: > > > matrix(c(1,

Re: [R] Saving objects inside a list

2011-01-03 Thread Jorge Ivan Velez
Hi Eduardo, Try r <- ls() result <- sapply(r, get) result HTH, Jorge On Mon, Jan 3, 2011 at 12:25 PM, Eduardo de Oliveira Horta <> wrote: > Hello there, > > any ideas on how to save all the objects on my workspace inside a list > object? > > For example, say my workspace is as follows > ls()

Re: [R] subset question

2010-12-29 Thread Jorge Ivan Velez
Hi Anjan, Try subset(d, gene %in% c("i1", "i2", "i3")) HTH, Jorge On Wed, Dec 29, 2010 at 4:55 PM, ANJAN PURKAYASTHA <> wrote: > Hi, > I'm having a problem with a step that should be pretty simple. > I have a dataframe, d, with column names : gene s1 s2 s3. The column > "gene" > stores an Id

Re: [R] Counting number of datasets and appending them

2010-12-29 Thread Jorge Ivan Velez
Hi Grace, Try something along the lines of do.call(rbind, lapply(1:maxi, function(x) get(paste('data', x, sep = "" HTH, Jorge On Wed, Dec 29, 2010 at 5:06 PM, Li, Grace <> wrote: > Hi there, > > I have a question on how to read a bunch of dataset, assign each of the > dataset to a matrix

Re: [R] Non-uniformly distributed plot

2010-12-23 Thread Jorge Ivan Velez
Hi Eric, You can try plot(x, y, log = 'xy') fit <- lm(log(y)~log(x)) abline(fit, col = 2, lty = 2) summary(fit) par(mfrow = c(2,2)) plot(fit) HTH, Jorge On Thu, Dec 23, 2010 at 5:55 PM, Eric Hu <> wrote: > Thanks David. I am reposting the data here. > > Eric > > > > Hi, > > > > I would like t

Re: [R] regression

2010-12-22 Thread Jorge Ivan Velez
Hi Ufuk, Using Michael's data, here is one more way of doing it: allmodels <- lapply(1:nrow(x), function(row) with(x, lm(y ~ ., data = x[-row,]))) allmodels To access the information contained in the model when the first row is removed, you can do summary(allmodels[[1]]) And, if you want to ha

Re: [R] vectorised recovery of strsplit value ??

2010-12-22 Thread Jorge Ivan Velez
Try sapply(strsplit(sampleIDs, "_"), "[", 1) HTH, Jorge On Wed, Dec 22, 2010 at 4:02 PM, maddox <> wrote: > > Dear Guru's > > My first steps with R have ground to a halt! I have a vector of sample > identifiers > > > sampleIDs > [1] "D1_1" "D1_2" "D1_3" "D1_4" "D1_5" "D1_6" "D1_7"

Re: [R] sample() issue

2010-12-20 Thread Jorge Ivan Velez
Hi Cory, Check out http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f HTH, Jorge On Mon, Dec 20, 2010 at 2:04 PM, cory n <> wrote: > > length(sample(25000, 25000*(1-.55))) > [1] 11249 > > > 25000*(1-.55) > [1] 11250 > > > length(sample(25000, 1125

Re: [R] Time Series of Histograms

2010-12-19 Thread Jorge Ivan Velez
Hi Enrico, Is this close to what you want to do? http://addictedtor.free.fr/graphiques/RGraphGallery.php?graph=109 HTH, Jorge On Sun, Dec 19, 2010 at 7:03 PM, Enrico R. Crema <> wrote: > Dear List, > > I have a set of distributions recorded at an equal interval of time and I > would like to p

Re: [R] check for item in vector

2010-12-13 Thread Jorge Ivan Velez
Hi CH, Check ?is.element ?"%in%" HTH, Jorge On Mon, Dec 13, 2010 at 9:48 AM, C.H. <> wrote: > Dear R users, > > Suppose I have an vector like this: > > animal <- c("Tiger","Panda") > > I would like to know is there any function that check for the > existence of certain item in a vector. > > e

Re: [R] break

2010-12-11 Thread Jorge Ivan Velez
If I understand correctly, the following should do it: lag.max2 <- function(object, n = 12){ matris <- matrix(NA, nrow = n) for(i in 1:n){ matris[i] <- ur.df(object, lags = i, type = "trend")@testreg$coefficients[i+3,4] if(matris[i]<0.1) break } # output c('lag' = i, 'p' = matris[i]) } a2 <

Re: [R] String to array

2010-12-09 Thread Jorge Ivan Velez
Try f <- function(string) as.numeric(strsplit(string, "- ")[[1]]) f(x) f(y) f(z) HTH, Jorge On Thu, Dec 9, 2010 at 9:24 AM, Romildo Martins <> wrote: > Hello, > > how convert x in xarray (numbers)? > > > x > [1] "0 - 13" > > y > [1] "11 - 23" > > z > [1] "220 - 9" > > xarray > [1] 0 13 > > ya

  1   2   3   4   5   6   7   8   9   >