Re: [R] Multiple if function

2015-09-16 Thread peter dalgaard
I think a more common idiom for the simpler case would be to use indexing vals <- c(0.1, 0.15, 0.2) mult <- vals[ASBclass] (However, some people are on the move to enforce mult <- vals[as.numeric(ASBclass)] because people who confuse factors and character variables get even more confused abo

Re: [R] help with old libraries

2015-09-16 Thread Uwe Ligges
On 15.09.2015 11:54, Pau Marc Muñoz Torres wrote: Hello everybody, I want to use Rapidr package, it is an old package that uses the package requires GenomicRanges version 1.14.4. The current version of the package is GenomicRanges 1.20.6. There is some way of having both the actual and the p

Re: [R] Drop in a Loop

2015-09-16 Thread Will Hopper
The data structure returned by optimx (that you're storing as gmmiv) is like a data frame, and stores the conversion code in the field convcode. So do something like this: gmmiv =Optimx() if (gmmiv$convcode ==0) { store[j,] = coef(gmmiv) } On Tue, Sep 15, 2015 at 3:12 PM, Olu Ola wrote: > Th

Re: [R] Multiple if function

2015-09-16 Thread Bert Gunter
Yes! Chuck's use of mapply is exactly the split/combine strategy I was looking for. In retrospect, exactly how one should think about it. Many thanks to all for a constructive discussion . -- Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not

[R] setTxtProgressBar clearing console (Windows RGui)

2015-09-16 Thread Jon Skoien
I have frequently noticed a strange effect when using the progress bar in a loop, that the console will sometimes be cleared. Whatever was printed before will then be inaccessible, which can be annoying when I want to check the progress and possible issues in a long script. It seems to be an in

Re: [R] by Function Result Factor Levels

2015-09-16 Thread Dario Strbenac
Good day, Yes, exactly. I found that aggregate is another alternative which doesn't require a package dependency, although the column formatting is less suitable, always prepending x. aggregate(warpbreaks[, 1], warpbreaks[, 2:3], function(breaks) c(Min = min(breaks), Med = median(breaks), Max

[R] mtext in the top left of margin

2015-09-16 Thread Hermann Norpois
Hello, for a multiple figures plot I am looking for the syntax to put text in the top left of the margin (of the plot). I want my testfunction plot.figure to place mtext in the top left of the red margin (created by box("figure", col="red")). Can anybody help? Thanks Hermann plot.figure <- func

[R] generate ordered categorical variable in R

2015-09-16 Thread thanoon younis
Dear R- users I want to generate ordered categorical variable vector with 200x1 dimension and from 1 to 4 categories and i tried with this code Q1=runif(200,1,4) the results are not just 1 ,2 3,4, but the results with decimals like 1.244, 2.342,4,321 and so on ... My question how can i generate a

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Michael Dewey
If I understand correctly ?sample On 16/09/2015 18:11, thanoon younis wrote: Dear R- users I want to generate ordered categorical variable vector with 200x1 dimension and from 1 to 4 categories and i tried with this code Q1=runif(200,1,4) the results are not just 1 ,2 3,4, but the results wi

Re: [R] by Function Result Factor Levels

2015-09-16 Thread David L Carlson
Actually x is the variable name since your function returned a vector of three values: > tbl <- aggregate(warpbreaks[, 1], warpbreaks[, 2:3], function(breaks) c(Min = > min(breaks), + Med = median(breaks), Max = max(breaks))) > str(tbl) 'data.frame': 6 obs. of 3 variables: $ wool : Facto

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Rui Barradas
Hello, Try ?sample. Hope this helps, Rui Barradas Em 16-09-2015 18:11, thanoon younis escreveu: Dear R- users I want to generate ordered categorical variable vector with 200x1 dimension and from 1 to 4 categories and i tried with this code Q1=runif(200,1,4) the results are not just 1 ,2 3,4

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread David L Carlson
There is a version of sample especially for integers: > Q1 <- matrix(sample.int(4, 200, replace=TRUE), 200) > str(Q1) int [1:200, 1] 1 4 4 2 3 3 4 4 2 3 ... - David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Marc Schwartz
> On Sep 16, 2015, at 12:11 PM, thanoon younis > wrote: > > Dear R- users > > I want to generate ordered categorical variable vector with 200x1 dimension > and from 1 to 4 categories and i tried with this code > > Q1=runif(200,1,4) the results are not just 1 ,2 3,4, but the results with > dec

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Bert Gunter
Yikes! The uniform distribution is a **continuous** distribution over an interval. You seem to want to sample over a discrete distribution. See ?sample for that, as in: sample(1:4,100,rep=TRUE) ## or for this special case and faster sample.int(4,size=100,rep=TRUE) Cheers, Bert Bert Gunter "Da

Re: [R] mtext in the top left of margin

2015-09-16 Thread Adams, Jean
You can use the coordinates of the plot region as fractions of the figure region, par("plt"), to define the adj= argument of mtext(). And you can use the number of lines of the plot margin to define the line= argument of mtext(). For example: plot.figure <- function() { par(mfrow=c(3, 1), mar=

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Marc Schwartz
> On Sep 16, 2015, at 1:06 PM, Bert Gunter wrote: > > Yikes! The uniform distribution is a **continuous** distribution over > an interval. You seem to want to sample over a discrete distribution. > See ?sample for that, as in: > > sample(1:4,100,rep=TRUE) > > ## or for this special case and fa

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Bert Gunter
Yes. Thanks Marc. I stand corrected. -- Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Wed, Sep 16, 2015 at 1:28 PM, Marc Schwartz wrote: > >> On Sep 16, 2015, at 1:06 PM, Bert Gunter wrote: >> >> Yikes!

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Bert Gunter
Nope. Take it back. I stand uncorrected. > system.time(z <-sample(1:10,1e6, rep=TRUE)) user system elapsed 0.045 0.001 0.047 > system.time(z <-sample.int(10,1e6,rep=TRUE)) user system elapsed 0.012 0.000 0.013 sample() has to do subscripting in the general case; sample.int d

[R] aggregate counting variable factors

2015-09-16 Thread Kai Mx
Hi everybody, >From a questionnaire, I have a dataset like this one with some 40 items: df1 <- data.frame(subject=c('user1','user2', 'user3', 'user4'), item1=c(0,1,2,5), item2=c(1,2,1,2), item3=c(2,3,4,0), item4=c(0,3,3,2), item5=c(5,5,5,5)) Users can choose an answer from 0 to 5 for each item.

[R] Get R-realisations for a 'custom' distribution

2015-09-16 Thread holograph via R-help
Hello all, I've been busy figuring out how to get realisations for a non-standard distribution in R. Define \theta=o (not 0). Consider f_x(x)=o*x for o in \sqrt{2/o}. Yet, I can't seem to find a way to get realisations for custom distributions. Can anyone help me out here? -- View this messa

[R] Error Message when using VarSelection in YaiImpute package with the randomForest

2015-09-16 Thread andrew haywood
Dear All, when using the following code x <- iris[,1:2] # Sepal.Length Sepal.Width y <- iris[,3:4] # Petal.Length Petal.Width vsel <- varSelection(x=x,y=y,nboot=5,yaiMethod="randomForest",useParallel=FALSE) I get the following error code Error in yai(x = xa, y = y, method = yaiMethod, bootst

[R] HELP IN GRAPHS - slip screen

2015-09-16 Thread Rosa Oliveira
Dear all, I’m trying to do a graph, 3 rows, 5 columns, with the design: # 3 4 5 6 #2 # 7 8 9 10 I had a code for 3 rows, 3 columns, with the design:: # 3 4 #2 # 7 8 and I tried to modify it, but I had no success :( I suppose the

Re: [R] generate ordered categorical variable in R

2015-09-16 Thread Marc Schwartz
> On Sep 16, 2015, at 3:40 PM, Bert Gunter wrote: > > Nope. Take it back. I stand uncorrected. > >> system.time(z <-sample(1:10,1e6, rep=TRUE)) > user system elapsed > 0.045 0.001 0.047 > >> system.time(z <-sample.int(10,1e6,rep=TRUE)) > user system elapsed > 0.012 0.000 0.013

Re: [R] Multiple if function

2015-09-16 Thread David Winsemius
On Sep 15, 2015, at 7:20 PM, Charles C. Berry wrote: > On Tue, 15 Sep 2015, Bert Gunter wrote: > >> Thanks to both Davids. >> >> I realize that these things are often a matter of aesthetics -- and >> hence have little rational justification -- but I agree with The Other >> David: eval(parse) se

Re: [R] Looking for Post-hoc tests (a la TukeyHSD) or interaction-level independent contrasts for survival analysis.

2015-09-16 Thread David Winsemius
On Sep 15, 2015, at 12:09 PM, Huot, Matthieu wrote: > Hi Tom > > I know the post is over 7-8 years old but I am having the same question. How > to do a post-hoc test like TukeyHSD on coxph type output. Create a new variable using the `interaction`-function, apply you contrasts to that object,

Re: [R] Multiple if function

2015-09-16 Thread Bert Gunter
I assume it's to return the vectors in their original order. -- Bert Bert Gunter "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." -- Clifford Stoll On Wed, Sep 16, 2015 at 2:10 PM, David Winsemius wrote: > > On Sep 15, 2015, at 7:20 PM, Charl

Re: [R] Multiple if function

2015-09-16 Thread Dénes Tóth
On 09/16/2015 04:41 PM, Bert Gunter wrote: Yes! Chuck's use of mapply is exactly the split/combine strategy I was looking for. In retrospect, exactly how one should think about it. Many thanks to all for a constructive discussion . -- Bert Bert Gunter Use mapply like this on large problem

Re: [R] HELP ERROR WHEN USING GAMMA2 IN VGLM TO SET MU AS AN INTERCEPT

2015-09-16 Thread Rolf Turner
On 17/09/15 09:50, Khedhaouiria Dikra wrote: Hi everyone, I'm trying to fit several models with the VGAM packages using the gamma2 function with an identity function link. .. For questions concerning a particular package it is usually best to contact the package maintainer (see maintai

Re: [R] Multiple if function

2015-09-16 Thread Bert Gunter
Dénes: A fair point! The only reason I have is ignorance -- I have not used data.table. I am not surprised that it and perhaps other packages (dplyr maybe?) can do things in a reasonable way very efficiently. The only problem is that it requires us to learn yet another package/paradigm. There may

[R] finding those elements of listA that are found in listB

2015-09-16 Thread John Sorkin
I have two structures. I think they are lists, but I am not sure. Both structures contain integers. I am trying to find those members of list b that are found in list a. I have tried to perform the search using grep, but I get an error. Please see code below. I would appreciate knowing how to se

Re: [R] finding those elements of listA that are found in listB

2015-09-16 Thread Richard M. Heiberger
I think you are looking for match or %in% (which is a based on match) > a <- sample(12) > b <- c(1, 3, 5, 11, 17) > a [1] 10 8 1 4 7 3 6 11 2 12 5 9 > b [1] 1 3 5 11 17 > [1] 1 > match(a, b) [1] NA NA 1 NA NA 2 NA 4 NA NA 3 NA > match(a, b, 0) [1] 0 0 1 0 0 2 0 4 0 0 3 0 > match