Re: [R] How to apply a function to subsets of a data frame *and* obtain a data frame again?

2011-08-17 Thread Nick Sabbe
You might want to look at package plyr and use ddply. HTH, Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove > -Original Message- > From: r-help-boun...@r-project.org [ma

Re: [R] glmnet

2011-08-10 Thread Nick Sabbe
y the variables selected in the previous step. Good luck! Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove > -Original Message- > From: r-help-boun...@r-project.org [ma

Re: [R] counting columns that fulfill specific criteria

2011-06-24 Thread Nick Sabbe
to name any variable t, as this is also the function for transposing a matrix, and could end up being confusing at the least. Second: for most practical purposes, it's better to leave out the *100. Good luck, Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure

Re: [R] problem (and solution) to rle on vector with NA values

2011-06-23 Thread Nick Sabbe
making the new behavior optional (through a new parameter na.action or similar, with the default the original behavior) is an option? Feel free to run your own version of rle in any case. I suggest you rename it, though, as it may cause problems for some packages. Nick Sabbe -- ping: nick.sa

Re: [R] Rcpp and Object Factories

2011-06-09 Thread Nick Sabbe
You might want to send this message to the Rcpp mailing list at: Rcpp-devel mailing list rcpp-de...@lists.r-forge.r-project.org https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel It will improve your chances of getting a swift (if not helpful) reply. Nick Sabbe -- ping

Re: [R] Simple order() data frame question.

2011-05-12 Thread Nick Sabbe
Try (df1[order(-df1[,2]),]) Adding the minus within the [ leaves out the column (in this case column 2). See ?"[". HTH. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove ---

Re: [R] Looping over graphs in igraph

2011-05-06 Thread Nick Sabbe
you're interested about, based on graph object g #for now I'm just returning edge and vertex counts return(c(v=vcount(g), e=ecount(g))) }) colnames(result)<-unique(dfr$Graph.ID) print(result) HTH, Nick Sabbe -- ping: nick.sa...@ugent.be

Re: [R] Lasso with Categorical Variables

2011-05-02 Thread Nick Sabbe
(invisible(factorsToDummyVariables.old (ds[20:30,]))) ## user system elapsed ## 2.110.002.15 If you have to do this quite often, the difference surely adds up... More improvements may be possible. This function only works if you don't include interactions, though. Nick Sabbe --

[R] abline outside of plot region

2011-04-29 Thread Nick Sabbe
orks. I set col.ticks to match the color of my abline (in the nonsimplified code), and this works too, but unfortunately, the label below the tick is not in this color, and a parameter for this is not present in axis. Suggestions for either? Note: I'm on windows 7 with R 2.13. Nick Sabbe -

Re: [R] Reference variables by string in for loop

2011-04-29 Thread Nick Sabbe
Hi Michael. This is a classic :-) ObjectsOfInterest<- list(one_df, two_df, three_df) for(namedf in ObjectsOfInterest){...} or probably even better sapply(ObjectsOfInterest, function(namedf){...}) hth. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coup

Re: [R] Assignments inside lapply

2011-04-27 Thread Nick Sabbe
No, that does not work. You cannot do assignment within (l)apply. Nor in any other function for that matter. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message

Re: [R] programming: telling a function where to look for the entered variables

2011-04-01 Thread Nick Sabbe
#columnsOfInterest or similar, and pass that instead of c(xvarname, yvarname) ) return(indextable) } myfunct.better("yes", lvarname="lvar", xvarname="xvar", yvarname="yvar", dataframe=Fulldf) HTH, Nick Sabbe -- ping: nick.sa...@ugent.be li

Re: [R] programming: telling a function where to look for the entered variables

2011-04-01 Thread Nick Sabbe
subset(Fulldf, lvar==subgroup, select=c("xvar","yvar")) Which should become something like (untested but should be close): Data.tmp <- Fulldf[Fulldf[,"lvar"]==subgroup, c("xvar","yvar")] This should be a lot easier to translate based on column n

Re: [R] choosing best 'match' for given factor

2011-03-31 Thread Nick Sabbe
. And similarly depending, I may be better still if you remove the rows that you're not interested in as well (some more but similar index trickery required then. HTH, Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring

Re: [R] Graph many points without hiding some

2011-03-31 Thread Nick Sabbe
ing box is in cube-form (scaling variables) #note: if you want to flip an axis, use -1 in the statement above axes3d() #Show axes title3d(main = main, sub=paste("Green is low", ulab, ", red is high") xlab = xlab, ylab = ylab, zlab = zlab)

Re: [R] a for loop to lapply

2011-03-30 Thread Nick Sabbe
d, like: given a matrix with two columns, create a vector holding the differences and the sums of the columns - I know this can be done without *apply as well, but apart from that it is a more attainable exercise). Good luck to you on that! HTH, Nick Sabbe -- ping: nick.sa...@ugent.be link: http:

Re: [R] A question on glmnet analysis

2011-03-25 Thread Nick Sabbe
he L1 penalty is not differentiable). Some 'solutions' exist (bootstrap, for one), but they have all been shown to have (statistical) properties that make them - at the least - doubtful. I know, because I'm working on this. Short answer: there is no way to do this (at this time). HTH (and ha

Re: [R] One to One Matching multiple vectors

2011-03-16 Thread Nick Sabbe
Hello Vincy. You probably want y[match(z,x)] Or, more instructional: whereAreZInX<-match(z, x) y[whereAreZInX] HTH, Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Mess

[R] Generic mixup?

2011-03-04 Thread Nick Sabbe
terrible misunderstanding of what comprises a generic function? Thx, Nick Sabbe -- ping: nick.sa...@ugent.be link: <http://biomath.ugent.be/> http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapp

Re: [R] speed up process

2011-02-25 Thread Nick Sabbe
b=names(mydata1)[k]) lapply(seq_along(mydata_list), function(j){ foo_reg(dat=mydata_list[[j]], xvar=ind.xvar, yvar=k, mycol=j, pos=mypos[j], name.dat=names(mydata_list)[j]) return(NULL) }) invisible(NULL) }) HTH, Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomat

Re: [R] glmnet with binary predictors

2011-02-03 Thread Nick Sabbe
t the 'best' value for the penalization parameter from the plot (see ?plot.cv.glmnet), or you can use some numerical argument to find the reasonable extreme value for the criterion. Really boilerplate, I guess. Good luck. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ug

[R] Preparing dataset for glmnet: factors to dummies

2011-02-01 Thread Nick Sabbe
taframe, I don't have the option to do this conversion before the imputation, so I really need the conversion itself to work quickly. Thanks, Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disappro

[R] Injecting code in a package?

2011-01-28 Thread Nick Sabbe
n-package bound copy of the function, I want to make sure that when I call pkg::plot.something, this works as before, but when, from within this function, pkg:: plot.something.internal is called, I want it to call _my_ version of it. Any takes? Nick Sabbe -- ping: nick.sa...@ugent.b

[R] get type functions (was: RE: plot not generic)

2011-01-28 Thread Nick Sabbe
Vito Muggeo (UniPa) [mailto:vito.mug...@unipa.it] Sent: vrijdag 28 januari 2011 14:42 To: Nick Sabbe Cc: r-help@r-project.org Subject: Re: [R] plot not generic dear Nick, getAnywhere("plot.glmnet") Note the message you get when you type methods(plot) ... >>> Non-visible

[R] plot not generic

2011-01-28 Thread Nick Sabbe
noticed that R does not recognize 'plot' as a generic function, and as such, showMethods does not work. This seems to conflict with the documentation for plot. So 2 questions: . How can I find the code of plot.glmnet . Why is plot not seen as generic? Thx.

Re: [R] Using a list as multidimensional indexer

2011-01-20 Thread Nick Sabbe
t;a",]. I tried some variants of Ind3<-list(Mm,"b",NULL) do.call("[", Ind3) But all of these return integer(0). So the actual new question is: how do I pass a 'missing' argument through a do.call? Thanks for any pointers, Nick Sabbe -- ping: nick.sa...@ugent

[R] Using a list as multidimensional indexer

2011-01-20 Thread Nick Sabbe
("b","g") This holds, for each dimension, an indexer for that dimension. Now I would like to get the element pointed at by the list. The obvious solutions don't seem to work, and I can't seem to get do.call to call the indexer ('[') on my mul

Re: [R] expand.grid

2011-01-19 Thread Nick Sabbe
-c(rv,NA) } #cat("levels with na: ", rv, "\n") return(rv) } expand.combs<-function(dfr, includeNA=FALSE, onlyOccurring=FALSE) { expand.grid(lapply(dfr, getLevels, includeNA, onlyOccurring)) } Thx. Nick Sabbe -- ping: nick.sa...@ugent.be link

[R] expand.grid

2011-01-19 Thread Nick Sabbe
t;). It would also be nice to be able to choose whether or not NA's are included. I'm convinced that some package holds a readymade solution, and I'm trying to switch from always writing my own stuff (get the number of levels per column, then use some apply magic) to using what is t

Re: [R] Repeating value occurence

2011-01-13 Thread Nick Sabbe
ern<- c(-1,0,1,0) rep(pattern, ceiling(n/length(pattern)))[1:n] If you want a sequence of random real numbers between -1 and 1, use runif(10, min=-1, max=1) Here's hoping I haven't just solved your homework... Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink:

Re: [R] Numbers in a string

2010-12-15 Thread Nick Sabbe
Hi Felipe, gsub("[^0123456789]", "", "AB15E9SDF654VKBN?dvb.65") results in "15965465". Would that be what you are looking for? Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent

Re: [R] problem accessing complex list data frames

2010-12-08 Thread Nick Sabbe
Hello Germán. You probably want something like: sapply(vmat, function(curMat){ curMat[,999] != 0 }) Or if you want the indices, just surround this with a which. HTH. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653

[R] Dataframe from list of similar lists: not _a_ way, but _the best_ way

2010-12-07 Thread Nick Sabbe
f R? Or is there any way in which this depends on the specifics of my function (for nontrivial functions and list sizes)? Thanks! Nick Sabbe -- ping: nick.sa...@ugent.be link: <http://biomath.ugent.be/> http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/

Re: [R] small problem in coding

2010-11-26 Thread Nick Sabbe
ent, you can access g by: lamda["g"] as in: > Q<-exp(lamda["g"]) It looks like you've got a misunderstanding of how R variables work, but maybe I just misunderstood your question... HTH, Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be

Re: [R] Simple Function

2010-11-10 Thread Nick Sabbe
and search for <<-, for more information). * apart from that: you may want to avoid the for loop here altogether: y[i:10]<-(i:10)+1 f[i:10]<-y[(i-1):9]/2 gives you the same result, but more in the R fashion (in general, you want to avoid explicit for loops in R) HTH, Nick Sabbe --

Re: [R] How to eliminate this for loop ?

2010-11-09 Thread Nick Sabbe
ld also like to see an example where they prove to be the better way to go (by any criteria, but preferably speed or perhaps other resource usage) Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapp

Re: [R] Help with Iterator

2010-11-09 Thread Nick Sabbe
hecked whether the rest of your code is OK) Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org

Re: [R] How to eliminate this for loop ?

2010-11-08 Thread Nick Sabbe
Whenever you use a recursion (that cannot be expressed otherwise), you always need a (for) loop. Apply and the like do not allow to use the intermediary results (i.e. a[i-1] to calculate a[i]). So: no, it cannot be avoided in your case, I guess. Nick Sabbe -- ping: nick.sa...@ugent.be link

Re: [R] Find index of a string inside a string?

2010-10-25 Thread Nick Sabbe
For simple searches, use grep with fixed=TRUE. Check ?grep. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help

Re: [R] if statement and truncated distribution

2010-10-25 Thread Nick Sabbe
return(val) } Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Sa

Re: [R] Random Integer Number in Uniform Distribution

2010-10-24 Thread Nick Sabbe
Check ?sample. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/264.59.36 -- Do Not Disapprove -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Gundala

Re: [R] printing a variable during a loop

2010-10-22 Thread Nick Sabbe
diately. A likely consequence will be that your code will run somewhat slower. For using some output as 'progress control' you definitely want to turn the option off. Nick Sabbe -- ping: nick.sa...@ugent.be link: http://biomath.ugent.be wink: A1.056, Coupure Links 653, 9000 Gent ring: 09/