Re: [R] Looping

2024-02-18 Thread Peter Langfelder
Try for (ind in 1:24) { data = read.csv(paste0("data", ind, ".csv")) ... } Peter On Mon, Feb 19, 2024 at 11:33 AM Steven Yen wrote: > > I need to read csv files repeatedly, named data1.csv, data2.csv,… data24.csv, > 24 altogether. That is, > > data<-read.csv(“data1.csv”) > … >

Re: [R] Count matrix of GSE146049

2023-04-02 Thread Peter Langfelder
It's a microarray data set, so I don't think you would want to apply an RNA-seq pipeline. You'd be better off applying a normalization appropriate for this type of microarray data. HTH, Peter On Sun, Apr 2, 2023 at 11:09 PM Anas Jamshed wrote: > > I want to get the count matrix of genes from >

Re: [R] confusion about dev.prev()

2022-12-05 Thread Peter Langfelder
Ah, thanks, got it. Misread the help again... Peter On Mon, Dec 5, 2022 at 9:38 PM Ivan Krylov wrote: > > В Mon, 5 Dec 2022 21:28:16 +0800 > Peter Langfelder пишет: > > > Open two devices, plot a plot, call dev.prev() and plot again. I > > would expect the second plo

[R] confusion about dev.prev()

2022-12-05 Thread Peter Langfelder
Hi all, I'm either confused about dev.prev() or there's a bug in it. Open two devices, plot a plot, call dev.prev() and plot again. I would expect the second plot to appear in the first device, but that is not what happens; both plots appear in the second device. Is this expected behavior or a

Re: [R] Subsetting a vector using an index with all missing values

2022-07-02 Thread Peter Langfelder
; > > x <- 1:10 > > x[ rep(NA_integer_, 3) ] > [1] NA NA NA > > x[ rep(NA, 3) ] > [1] NA NA NA NA NA NA NA NA NA NA > > -Bill > > > On Fri, Jul 1, 2022 at 8:31 PM Peter Langfelder > wrote: >> >> Hi all, >> >> I stumbled on subs

Re: [R] Checking a function for undeclared variables

2022-04-05 Thread Peter Langfelder
Thanks! Peter On Tue, Apr 5, 2022 at 6:01 PM Jeff Newmiller wrote: > > ?codetools::findGlobals > > On April 5, 2022 5:36:54 PM PDT, Peter Langfelder > wrote: > >Hi all, > > > >I'd like to check a function for undeclared global variables using > >somethin

Re: [R] Sum every n (4) observations by group

2021-12-19 Thread Peter Langfelder
I'm not sure I understand the task, but if I do, assuming your data frame is assigned to a variable named df, I would do something like sumNs = function(x, n) { if (length(x) %%n !=0) stop("Length of 'x' must be a multiple of 'n'.") n1 = length(x)/n ind = rep(1:n1, each = n) tapply(x,

Re: [R] Random Forest: OOB performance = test set performance?

2021-04-10 Thread Peter Langfelder
I think the only thing you are doing wrong is not setting the random seed (set.seed()) so your results are not reproducible. Depending on the random sample used to select the training and test sets, you get slightly varying accuracy for both, sometimes one is better and sometimes the other. HTH,

Re: [R] about a p-value < 2.2e-16

2021-03-18 Thread Peter Langfelder
I thinnk the answer is much simpler. The print method for hypothesis tests (class htest) truncates the p-values. In the above example, instead of using wilcox.test(rnorm(100), rnorm(100, 2), exact=TRUE) and copying the output, just print the p-value: tst = wilcox.test(rnorm(100), rnorm(100, 2),

Re: [R] Does anyone have any use for this?

2021-01-01 Thread Peter Langfelder
This would certainly simplify and make more readable some of my code where I create multiple versions of the same plot calling the same function with minor variations of a few of many arguments. Thanks! Peter On Fri, Jan 1, 2021 at 12:20 PM Bert Gunter wrote: > Hi all: > > In the course of

Re: [R] Error pvclust package: Error in hclust(distance, method = method.hclust)

2020-12-14 Thread Peter Langfelder
I don't use pvclust but from a cursory reading and from the error indicating bootstrap I am guessing that pvclust carries out some sort of a sampling of the features on which you cluster. Since you only retain two features (coordinates), the sampling necessarily results in just one feature being

Re: [R] Assigning cores

2020-09-03 Thread Peter Langfelder
The big question is whether each worker or thread uses parallel processing itself, or whether it uses resources like cache in which case 20 threads fighting over the cache would slow you down substantially. If your simulations use operations implemented in BLAS or LAPACK, be aware that some R

Re: [R] custom function gives unexpected result - for me

2020-04-17 Thread Peter Langfelder
You need 1:(m-1) in your function. The operator : has precedence over -: > 1:3-1 [1] 0 1 2 > 1:(3-1) [1] 1 2 Happened to me a few times as well before I remembered. HTH, Peter On Fri, Apr 17, 2020 at 3:50 PM Monica Palaseanu-Lovejoy wrote: > > Hi, > > I wrote a relatively simple function. If

Re: [R] POSIX system oddities

2020-03-29 Thread Peter Langfelder
The time has changed from "standard" (EST) to "Daylight saving" (EDT) which shaves off 1 hour. Peter On Sun, Mar 29, 2020 at 5:03 PM Sebastien Bihorel via R-help < r-help@r-project.org> wrote: > Hi, > > Why is there less number of seconds on 03/10/2019 in the internal POSIX > system? The

Re: [R] Add labels to dendogram

2020-03-26 Thread Peter Langfelder
Your code does not work because Tag is not numeric. You need to exclude Tag from the data frame df and instead assign it as rownames. Also, dist requires a numeric matrix, not data frame. df = as.matrix(data.frame(Healthy, Tumour, Metastasis)) or df = cbind(Healthy, Tumour, Metastasis)

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-15 Thread Peter Langfelder
one of those highly correlated ones. > > I tried to do your code: > > tree = hclust(1-calc.rho, method = "average") > Error in if (is.na(n) || n > 65536L) stop("size cannot be NA nor > exceed 65536") : > missing value where TRUE/FALSE needed > >

Re: [R] Remove highly correlated variables from a data frame or matrix

2019-11-14 Thread Peter Langfelder
I suspect that you want to identify which variables are highly correlated, and then keep only "representative" variables, i.e., remove redundant ones. This is a bit of a risky procedure but I have done such things before as well sometimes to simplify large sets of highly related variables. If your

Re: [R] reading in csv files, some of which have column names and some of which don't

2019-08-13 Thread Peter Langfelder
If the data are numeric (or at least some columns are numeric), a brute force solution is to read a file once with header = FALSE, check the relevant column(s) for being numeric, and if they are not numeric, re-read with header = TRUE. Alternatively, if you know the column names (headers)

Re: [R] read

2019-08-08 Thread Peter Langfelder
I would remove the quotes using sub, something like # Read the file as text lines text = readLines(con = file(yourFileName)) # Remove the offending quotes text = gsub("'|\"", "", text) # Concatenate and turn into a data frame concat = paste(text, collapse = "\n") df = read.table(text = concat,

Re: [R] bizarre color space conversion problem

2019-07-18 Thread Peter Langfelder
Sarah, if you haven't done so already, please do us (OpenBLAS users) a big favor and report the bug, either to Fedora or directly to OpenBLAS maintainers. Peter On Thu, Jul 18, 2019 at 11:46 AM Sarah Goslee wrote: > > Wow. You are entirely correct. I would not have been able to pinpoint > the

Re: [R] Define pch and color based on two different columns

2019-04-09 Thread Peter Langfelder
; <https://mailtrack.io?utm_source=gmail_medium=signature_campaign=signaturevirality5;> > Sender > notified by > Mailtrack > <https://mailtrack.io?utm_source=gmail_medium=signature_campaign=signaturevirality5;> > 04/09/19, > 10:01:53 PM > > On Tue, Ap

Re: [R] Define pch and color based on two different columns

2019-04-09 Thread Peter Langfelder
Sorry for being late to the party, but has anyone suggested a minor but important modification of the code from stack exchange? xyplot(mpg ~ wt | cyl, panel = function(x, y, ..., groups, subscripts) { pch <- mypch[factor(carb)[subscripts]] col <-

Re: [R] Help with gsub function

2019-03-15 Thread Peter Langfelder
If you want to remove just the hyphen, why not do sub("-", "", tb2a$TID) sub("-", "", "73-017323") [1] "73017323" Am I missing something? Peter On Fri, Mar 15, 2019 at 12:46 PM Bill Poling wrote: > > Good afternoon. > > sessionInfo() > #R version 3.5.3 (2019-03-11) > #Platform:

Re: [R] Confusion Table

2019-01-16 Thread Peter Langfelder
The lazy way is to do tst_tab = tst_tab[c(2,1), c(2,1)] The less lazy way is something like tst_tab <- table(predicted = factor(tst_pred, levels = c("Yes", "No")), actual = factor(default_tst$default, levels = c("Yes", "No"))) Peter On Wed, Jan 16, 2019 at 4:39 PM wrote: > > R-Help > > > >

Re: [R] randomForest out of bag prediction

2019-01-12 Thread Peter Langfelder
See inline. On Sat, Jan 12, 2019 at 9:56 AM Witold E Wolski wrote: > ypred_oob <- predict(diachp.rf) AFAIK these are, indeed, the out-of-bag predictions. > dataX <- data %>% select(-quality) # remove response. > ypred <- predict( diachp.rf, dataX ) These are not out of bag predictions. dataX

Re: [R] Using apply

2018-10-30 Thread Peter Langfelder
It should be said that for many basic statistics, there are faster functions than apply, for example here you want sum = colSums(x) As already said, for sum of squares you would do colSums(x^2). Many useful functions of this kind are implemented in package matrixStats. Once you install it,

Re: [R] remove text from nested list

2018-10-25 Thread Peter Langfelder
You should be more specific about what you want to replace and with what. The pattern you use, namely "[0-9][0-9]/[0-9[0-9].*com", does not (AFAICS) match any of the strings in your data, so don't be surprised that your commands do not change anything. If you have a correct pattern and

Re: [R] GLM Model Summary

2018-10-16 Thread Peter Langfelder
The coefficients are best obtained as summary(Model)$coefficients. This is a matrix can than be saved as a csv file and opened in excel or other spreadsheet software. HTH, Peter On Tue, Oct 16, 2018 at 9:44 AM Neslin, Scott A. wrote: > > R-Help: > > We are working with your GLM R package. The

Re: [R] Set attributes for object known by name

2018-10-10 Thread Peter Langfelder
oops, I think the right code would be x = get(varname) attr(x, "foo") = "bar" assign(varname, x) On Wed, Oct 10, 2018 at 9:30 PM Peter Langfelder wrote: > I would try something like > > x = get(myvarname) > attr(x, "foo") = "bar" > assign(

Re: [R] Set attributes for object known by name

2018-10-10 Thread Peter Langfelder
I would try something like x = get(myvarname) attr(x, "foo") = "bar" assign(varname, x) HTH, Peter On Wed, Oct 10, 2018 at 9:15 PM Marc Girondot via R-help < r-help@r-project.org> wrote: > Hello everybody, > > Has someone the solution to set attribute when variable is known by name ? > >

Re: [R] tibble question with a mean

2018-09-20 Thread Peter Langfelder
I don't know tibble, so I'll do the same with a plain data frame: a = data.frame(x=LETTERS[1:4],y=1:4,z=rnorm(4),a=c("dog","cat","tree","ferret")) > a x y z a 1 A 1 -0.08264865dog 2 B 2 0.32344426cat 3 C 3 -0.80416061 tree 4 D 4 1.27052529 ferret > mean(a[2:3]) [1] NA

Re: [R] sink() output to another directory

2018-09-13 Thread Peter Langfelder
(). Technically, print() sends output to a device called "standard output" which is usually screen, but it can be changed to a file (_any_ writable file) using the sink() command. Hope this helps, Peter On Thu, Sep 13, 2018 at 4:35 PM Rich Shepard wrote: > On Thu, 13 Sep 2018, Peter Lan

Re: [R] sink() output to another directory

2018-09-13 Thread Peter Langfelder
There is no path in print. The path (file) is set in sink(). Peter On Thu, Sep 13, 2018 at 4:35 PM Rich Shepard wrote: > On Thu, 13 Sep 2018, Peter Langfelder wrote: > > > Remove the / from the print command, it does not belong there. > > Peter, > >So the print(

Re: [R] sink() output to another directory

2018-09-13 Thread Peter Langfelder
For the second time: Rich, there should be no slash in the print() command. Use the form sink("../directory/file") print(summary(foo)) ### no slashes here sink(NULL) Peter On Thu, Sep 13, 2018 at 7:12 PM Rich Shepard wrote: > On Thu, 13 Sep 2018, Henrik Bengtsson wrote: > > >>

Re: [R] sink() output to another directory

2018-09-13 Thread Peter Langfelder
Remove the / from the print command, it does not belong there. sink("../directory/file.txt"); print(summary(foo)) sink(NULL) On Thu, Sep 13, 2018 at 4:03 PM Rich Shepard wrote: > On Thu, 13 Sep 2018, Rich Shepard wrote: > > > sink('example-output.txt') > > print(summary(df)) > > sink() > >

Re: [R] histogram in GNU R....

2018-09-07 Thread Peter Langfelder
A simpler short term solution is to execute dev.off() and look for the plot in file Rplots.pdf in the current directory. Depending on the OS of the local computer, you should be able to point a file browser at the EC instance and simply click the file to open in in a pdf viewer on the local

Re: [R] R shared library (/usr/lib64/R/lib/libR.so) not found.

2018-08-23 Thread Peter Langfelder
On Thu, Aug 23, 2018 at 7:33 AM Berwin A Turlach wrote: > > G'day Rolf, > > On Thu, 23 Aug 2018 23:34:38 +1200 > Rolf Turner wrote: > > > I guess I should have said --- I did > > > > sudo make prefix=/usr install > > > > which puts stuff into /usr rather than into /usr/local. > > ??? > > I

Re: [R] [FORGED] Re: bar plot add space to group data

2018-08-19 Thread Peter Langfelder
On Sun, Aug 19, 2018 at 7:15 AM wrote: > > August 19, 2018 4:58 AM, "Peter Langfelder" > wrote: > > > To the OP, try formatting the data to be plotted as a matrix, not as a > > vector > > CSV data provided in a previous message; is not the data formatt

Re: [R] [FORGED] Re: bar plot add space to group data

2018-08-18 Thread Peter Langfelder
My guess is that space has no effect because (1) the first element is zero and (2) the code in OP's message has barplot(gceac[,3], ... i.e. barplot does not see a matrix, only a vector. To the OP, try formatting the data to be plotted as a matrix, not as a vector, then the space argument should

Re: [R] How deep into function calls does trycatch() work

2018-08-16 Thread Peter Langfelder
AFAIK a try or tryCatch will intercept the error thrown by stop(). Why not try it and see if it works? Peter On Thu, Aug 16, 2018 at 1:05 PM Roy Mendelssohn - NOAA Federal via R-help wrote: > > Hi All: > > I am using another package in a project I have. Because of that, I have no > control on

Re: [R] Fast matrix multiplication

2018-08-13 Thread Peter Langfelder
On Mon, Aug 13, 2018 at 12:18 PM Ista Zahn wrote: > > On Mon, Aug 13, 2018 at 2:41 PM Ravi Varadhan wrote: > > > > Hi Ista, > > Thank you for the response. I use Windows. Is there a pre-compiled > > version of openBLAS for windows that would make it easy for me to use it? > > Not sure. If you

Re: [R] Mysterious seg fault.

2018-08-11 Thread Peter Langfelder
Segfaults are not always repeatable. You may have an undefined pointer that sometime points into unreachable or unallocated memory, causing a segfault, and sometimes may point into valid memory, without causing a segfault. You may want to read

Re: [R] Trying to Generalize a Function in R

2018-08-09 Thread Peter Langfelder
: > AVB[["AVB.Close"]] > and I got: > Error in AVB[["AVB.Close"]] : subscript out of bounds > Are you assuming that AVB is a data frame? I do not think AVB is a data > frame. Is there a way > for me to check? > Thanks, > Bob > > On

Re: [R] Trying to Generalize a Function in R

2018-08-09 Thread Peter Langfelder
If I understand it correctly, the function getSymbols creates a variable with the name being the stock symbol. Then use the function get(symbol) to retrieve the value of the variable whose name is contained in the character string `symbol'. Assign that to a variable (e.g. AVB). You may also have

Re: [R] subsetting ls() as per class...

2018-07-28 Thread Peter Langfelder
Looking at ?rm, my solution would be something like rm(list = grep("\\.NS$", ls(), value = TRUE)) But test it since I have not tested it. Peter On Fri, Jul 27, 2018 at 10:58 PM akshay kulkarni wrote: > > dear memebers, >I am using R in AWS linux instance for

Re: [R] OT --- grammar.

2018-06-24 Thread Peter Langfelder
I would use "the number of degrees of freedom is defined... ". Peter On Sun, Jun 24, 2018 at 2:46 PM Rolf Turner wrote: > > > Does/should one say "the degrees of freedom is defined to be" or "the > degrees of freedom are defined to be"? > > Although value of "degrees of freedom" is a single

Re: [R] Hacked

2018-04-17 Thread Peter Langfelder
I got some spam emails after my last post to the list, and the emails did not seem to go through r-help. The spammers may be subscribed to the r-help, or they get the poster emails from some of the web copies of this list (nabble or similar). Peter On Tue, Apr 17, 2018 at 11:37 AM, Ulrik Stervbo

[R] WGCNA package installation segmentation fault

2018-04-12 Thread Peter Langfelder
Hi all, a user contacted me about a segfault when installing WGCNA package dowloaded from CRAN. I also see a segfault like that on certain installs of R. The package passes all CRAN checks, so presumably this has something to do with the R installation or environment. The R versions here are not

Re: [R] parallel computing with foreach()

2017-12-06 Thread Peter Langfelder
Your code generates an error that has nothing to do with dopar. I have no idea what your function stack is supposed to do; you may be inadvertently calling utils::stack which would produce this kind of error: > stack(1:25, RAT = FALSE) Error in data.frame(values = unlist(unname(x)), ind,

Re: [R] Rcpp, dyn.load and C++ problems

2017-12-03 Thread Peter Langfelder
I would go to the source, in this case Dirk Eddelbuettel's (I hope I spelled it correctly) documentation for Rcpp: http://dirk.eddelbuettel.com/code/rcpp/Rcpp-attributes.pdf Note that you need to do sourceCpp("logistic_map.cpp") in R instead of building and dyn.load()-ing the object. HTH,

Re: [R] mystery "158"

2017-11-21 Thread Peter Langfelder
Your data frame fam contains factors. Turn it into character strings using fam$Family = as.character(fam$Family) and try again. It may be helpful if you read up on R's factors, see ?factor. HTH, Peter On Tue, Nov 21, 2017 at 2:14 PM, Glen Forister wrote: > This is a

Re: [R] tcltk problems

2017-11-17 Thread Peter Langfelder
Rolf, looking at the configure script I believe you need to specify --with-tcl-config=/usr/lib/tcl8.6/tclConfig.sh and similarly --with-tk-config= HTH, Peter On Fri, Nov 17, 2017 at 8:43 PM, Rolf Turner wrote: > On 18/11/17 17:00, Erin Hodgess wrote: >> >> When I

Re: [R] valid package repositories

2017-10-02 Thread Peter Langfelder
On Mon, Oct 2, 2017 at 7:47 AM, Federico Calboli wrote: > > Thus my question: when can I consider a library to be properly published and > really publicly available? CRAN and BioConductor are clearly gold standards. > What about Github? I am currently using the

Re: [R] Converting SAS Code

2017-09-29 Thread Peter Langfelder
On Fri, Sep 29, 2017 at 2:32 PM, peter dalgaard wrote: > >> On 29 Sep 2017, at 22:43 , MacQueen, Don wrote: >> >> I used to use SAS a lot, but I don't know what the line >> *Yield Champagin; >> does. > > Nothing. It's a comment... Fortune nomination!

Re: [R] building random matrices from vectors of random parameters

2017-09-27 Thread Peter Langfelder
I would try something like n = 5 a <- rnorm(n,0.8,0.1) so <- rnorm(n,0.5,0.1) m <- rnorm(n,1.2,0.1) mats = mapply(function(sa1, so1, m1) matrix(c(0,sa1*m1,so1,sa1),2,2,byrow=T), a, so, m, SIMPLIFY = FALSE) > mats [[1]] [,1] [,2] [1,] 0.000 0.9129962 [2,]

Re: [R] A problem with order() function in R

2017-07-17 Thread Peter Langfelder
I think you want rank, not order. > x <- c(19,17,23,11) > order(x) [1] 4 2 1 3 > rank(x) [1] 3 2 4 1 See help(order) and help(rank) for the difference. Peter On Mon, Jul 17, 2017 at 7:58 PM, Jesadaporn Pupantragul wrote: > Hello r-help > I am learning R and use R-studio.

Re: [R] Error in WGCNA package

2017-07-09 Thread Peter Langfelder
First, please read WGCNA FAQ at https://labs.genetics.ucla.edu/horvath/CoexpressionNetwork/Rpackages/WGCNA/faq.html regarding using RNA-seq and other count data. Second, if you insist on using WGCNA on raw count data (which I don't recommend), use something like storage.mode(datExpr) = "double"

Re: [R] Error in y - ymean : non-numeric argument to binary operator

2017-05-26 Thread Peter Langfelder
This is a bit of a shot in the dark since I haven't used randomForest in several years, but I seem to recall that running randomForest through the formula interface was asking for trouble... Try not using the formula interface and specify the x, y, xtest arguments directly. Peter On Fri, May 26,

Re: [R] Override/Insert (Change) a value (default value) inside a function

2017-03-11 Thread Peter Langfelder
On Sat, Mar 11, 2017 at 2:11 PM, Mohammad Tanvir Ahamed via R-help wrote: > Thanks for reply. > as I said , the function in the package is like > myplot <- function(x,y) { plot(x,y) } > > not like > myplot <- function(x,y) { plot(x,y,...) } > > And I cant change the function

Re: [R] Error: long vectors (argument 1) are not supported in .Fortran

2017-02-03 Thread Peter Langfelder
Just to set the record straight, WGCNA is a CRAN package. As to Ankush's question - the current WGCNA version does not support analysis of more than about 46300 nodes (probes) in one block. You have two options: 1. filter out some of the least-informative probes (e.g., probes with lowest mean

Re: [R] R in raspberry Pi

2017-01-02 Thread Peter Langfelder
I can see the file under this link: http://www.floppybunny.org/robin/web/rbook/online_chapters/r_and_the_raspberry_pi.pdf Make sure the (English) words are not split - my first attempt contained raspber_ry and thus it failed. Peter On Mon, Jan 2, 2017 at 5:10 PM, John Sorkin

Re: [R] Gobbling up a repeating, irregular list of data

2016-11-10 Thread Peter Langfelder
It's not clear whether your numbers are tab or space-separated, I will assume space-separated. My lowtech (and not R) solution would be to dump the output into a text file (call it data.in), then run a sed command to first replace two initial spaces from each line, then replace initial spaces with

Re: [R] creating lists of random matrices

2016-11-09 Thread Peter Langfelder
Add a simplify = FALSE to the call to replicate, and you'll get a list. replicate(5, matrix(rnorm(4), 2, 2), simplify = FALSE) Peter On Wed, Nov 9, 2016 at 10:45 AM, Rui Barradas wrote: > Hello, > > I also thought of replicate() but it creates an 2x2x5 array, not a

Re: [R] separate commands by semicolon

2016-09-17 Thread Peter Langfelder
On Sat, Sep 17, 2016 at 2:12 PM, David Winsemius wrote: > > > Not entirely clear. If you were intending to just get character output then > you could just use: > > strsplit(txt, ";") > > If you wanted parsing to an R expression to occur you could pass through > sapply

Re: [R] Visualizing and clustering one half of a symmetric matrix

2016-09-15 Thread Peter Langfelder
Do not set the upper (or lower) triangle to NA. Simply supply the full matrix to pheatmap. I am not an expert on pheatmap but looking at the manual you should supply clustering_distance_rows = "none", clustering_distance_cols = "none" or something like that to make pheatmap interpret the matrix as

Re: [R] Efficiently parallelize across columns of a data.table

2016-08-19 Thread Peter Langfelder
Last time I looked (admittedly a few years back), on unix-alikes (which you seem to be using, based on your use of top), foreach/doParallel used forking. This means each worker gets a copy of the entire R session, __but__ modern operating systems do not actually copy on spawn, they only copy on

Re: [R] Reduce woes

2016-07-27 Thread Peter Langfelder
If you have a simple list of vectors (call it lst), use lengths = sapply(lst, length) In general, you may want to look at functions lapply and sapply which apply a function over a list, in this case the function length(). Peter On Wed, Jul 27, 2016 at 8:20 AM, Stefan Kruger

[R] Fwd: How to make the "apply" faster

2016-07-09 Thread Peter Langfelder
Forgot to cc the list... -- Forwarded message -- From: Peter Langfelder <peter.langfel...@gmail.com> Date: Sat, Jul 9, 2016 at 1:32 PM Subject: Re: [R] How to make the "apply" faster To: Debasish Pai Mazumder <pai1...@gmail.com> You could try the follo

Re: [R] Element-by-element operation (adding)

2016-05-22 Thread Peter Langfelder
Two solutions... v + matrix(b, nrow(v), ncol(v), byrow = TRUE) or t(apply(v, 1, `+`, b)) Peter On Sun, May 22, 2016 at 10:39 PM, Steven Yen wrote: > Hi all, need help below. Thank you. > > > # Matrix v is 5 x 3 > > # Vector b is of length 3 > > # I like to add b[1] to

Re: [R] Grep command

2016-05-19 Thread Peter Langfelder
I use my own functions multiGrep and multiGrepl: multiGrep = function(patterns, x, ..., sort = TRUE, invert = FALSE) { if (invert) { out = multiIntersect(lapply(patterns, grep, x, ..., invert = TRUE)) } else out = unique(unlist(lapply(patterns, grep, x, ..., invert = FALSE))); if

Re: [R] Same sum, different sets of integers

2016-04-27 Thread Peter Langfelder
I came up with this, using recursion. Short and should work for n greater than 9 :) Peter sumsToN = function(n) { if (n==1) return(1); out = lapply(1:(n-1), function(i) { s1 = sumsToN(n-i); lapply(s1, c, i) }) c(n, unlist(out, recursive = FALSE)); } > sumsToN(4) [[1]] [1] 4

Re: [R] using apply to a data frame

2016-04-07 Thread Peter Langfelder
Use lapply or sapply. A data frame is also a list with each component representing one column; lapply/sapply will apply the function to each column. Peter On Thu, Apr 7, 2016 at 1:25 PM, John Sorkin wrote: > > ‪‪I would like to apply a function, fract, to the

Re: [R] How to read ./configure messages

2016-02-01 Thread Peter Langfelder
I am not overly familar with Mint, but you need the "development version" of the readline library. If you have a GUI package manager installed, open it and search for readline. You should see a version that ends with -dev or -devel; you need to install that. HTH, Peter On Mon, Feb 1, 2016 at

Re: [R] Thread parallelism and memory management on shared-memory supercomputers

2015-12-30 Thread Peter Langfelder
I'm not really an expert, but here are my 2 cents: To the best of my limited knowlede, there is no direct way of ensuring that the total memory being requested by N workers remains below a certain threshold. You can control the number of child processes forked by foreach/doPar in the

Re: [R] How do we do correlation for big matrices?

2015-12-26 Thread Peter Langfelder
My guess is that a mapply would take forever to run. I would split it up into smaller blocks - not too large so the calculation can fit into the RAM, and not too small to make the calculation tun too long. Say 500 columns per block, that way each correlation matrix takes up 500*500*8 bytes = 1.9

Re: [R] F Distribution

2015-12-21 Thread Peter Langfelder
You want to use qf which gives you the value at a given percentile. pf gives you the p-value for a given value of F (inverse) > qf(0.95, 1, 1) [1] 161.4476 > pf(161.4476, 1, 1) [1] 0.95 Peter On Mon, Dec 21, 2015 at 11:51 AM, Robert Sherry wrote: > > When I use a

Re: [R] WGCNA cluster

2015-11-18 Thread Peter Langfelder
Hi Giovanni, please follow Tutorial I, section 3 (particularly 3d, "Summary output of network analysis results") at http://labs.genetics.ucla.edu/horvath/CoexpressionNetwork/Rpackages/WGCNA/Tutorials/index.html . This will show you how to output module membership of each CpG into a file. If you

Re: [R] c(1:n, 1:(n-1), 1:(n-2), ... , 1)

2015-09-17 Thread Peter Langfelder
Not sure if this is slicker or easier to follow than your solution, but it is shorter :) do.call(c, lapply(n:1, function(n1) 1:n1)) Peter On Thu, Sep 17, 2015 at 11:19 AM, Dan D wrote: > Can anyone think of a slick way to create an array that looks like c(1:n, > 1:(n-1),

Re: [R] glm help

2015-08-21 Thread Peter Langfelder
, Aug 20, 2015 at 10:47 PM, Peter Langfelder peter.langfel...@gmail.com wrote: On Thu, Aug 20, 2015 at 10:04 PM, Bert Gunter bgunter.4...@gmail.com wrote: I noticed you made two data-frames, ‘my4s' and ‘my4S'. The `my4S` was built with `cbind` which would create a matrix (probably a character

Re: [R] glm help

2015-08-20 Thread Peter Langfelder
On Thu, Aug 20, 2015 at 10:04 PM, Bert Gunter bgunter.4...@gmail.com wrote: I noticed you made two data-frames, ‘my4s' and ‘my4S'. The `my4S` was built with `cbind` which would create a matrix (probably a character matrix) rather than a data frame. False. There is a data.frame method for

Re: [R] Newbie question: error message with install.packages

2015-08-20 Thread Peter Langfelder
From an older post by Uwe Ligges: Anyway: R tried to download the package but got an html page, obviously, hence either the mirror you are using is corrupted or someone in between (like some proxy?) delivers html pages rather than packages... In other words, check your proxy/internet settings,

Re: [R] Help with Plot

2015-08-04 Thread Peter Langfelder
Try removing the line x - x[order(x[,1], decreasing=TRUE),] Peter On Tue, Aug 4, 2015 at 10:58 AM, April Smith aprilgracesm...@gmail.com wrote: Let me just preface that everything I know about writing code for R is self taught so this may be really basic but I can't figure it out! I am

Re: [R] Splitting lines in R script

2015-08-02 Thread Peter Langfelder
R does not need a semicolon or other character to terminate a command; if a line can be interpreted as a complete command, it will (first line in your second example). Also note that the first example may not produce what you want (if your second example is any indication) - the result of

Re: [R] matrix manipulation

2015-07-16 Thread Peter Langfelder
Hi Terry, maybe I'm missing something, but why not define a matrix BB = V'B; then t(B) %*% V = t(BB), then your problem reduces to finding A such that t(BB) %*% A = 0? Peter On Thu, Jul 16, 2015 at 10:28 AM, Therneau, Terry M., Ph.D. thern...@mayo.edu wrote: This is as much a mathematics as an

Re: [R] data$variable=factor(....) NA NA NA

2015-07-11 Thread Peter Langfelder
There are two issues here. First, your original factor seems to have 4 levels: F, M, F, M. Note the extra space in front of the first two F and M. You may want to fix that first: gender.fixed = sub( , , as.character(data$gender)) Check that everything is correct by typing table(gender.fixed)

Re: [R] Correlation matrix for pearson correlation (r,p,BH(FDR))

2015-06-18 Thread Peter Langfelder
You have multiple options. I will advertise my own solution - install the package WGCNA, installation instructions at http://labs.genetics.ucla.edu/horvath/CoexpressionNetwork/Rpackages/WGCNA/#cranInstall then you can use the function cp = corAndPvalue(t(genes), t(features)). You need to

Re: [R] creating a distinct zip file

2015-02-21 Thread Peter Langfelder
On Fri, Feb 20, 2015 at 6:56 PM, Rolf Turner r.tur...@auckland.ac.nz wrote: On 21/02/15 15:02, Jeff Newmiller wrote: R CMD INSTALL --build packagename That will create a *.tar.gz file, not a *.zip file. The latter being what Erin wanted, if I understand correctly. It depends on her

Re: [R] Swirl course crashes

2015-02-04 Thread Peter Langfelder
It's hard to say from your description what the situation is. The error simply means the plot area is too small for the figure margins to fit. Try closing the graphics (plot) window before you run the section that causes the error, or you can try maximizing the plotting window. You can also

Re: [R] Package corpcor: Putting symmetric matrix entries in vector

2015-01-30 Thread Peter Langfelder
If you have a symmetric matrix, you can work with the upper triangle instead of the lower one, and you get what you want by simply using as.vector(A[upper.tri(A)]) Example: a = matrix(rnorm(16), 4, 4) A = a + t(a) A [,1] [,2] [,3][,4] [1,] 0.3341294 0.5460334

Re: [R] Matrix element-by-element multiplication

2015-01-07 Thread Peter Langfelder
You can create a suitable matrix bb as below (note the byrow = TRUE argument) aa-matrix(1:30,nrow=10,ncol=3); aa bb-matrix(c(100,100,1),nrow=10,ncol=3, byrow = TRUE); bb dim(aa) dim(bb) aa * bb You can also use matrix multiplication, but that;s slightly more involved:

Re: [R] Matrix element-by-element multiplication

2015-01-07 Thread Peter Langfelder
On Wed, Jan 7, 2015 at 3:15 PM, Peter Langfelder peter.langfel...@gmail.com wrote: You can create a suitable matrix bb as below (note the byrow = TRUE argument) aa-matrix(1:30,nrow=10,ncol=3); aa bb-matrix(c(100,100,1),nrow=10,ncol=3, byrow = TRUE); bb dim(aa) dim(bb) aa * bb You can

Re: [R] Loading a rda file for predicton

2014-10-13 Thread Peter Langfelder
see help(load) and pay particular attention to what the function returns: the names of the loaded objects, not the object(s) themselves. You have to use predict(fit,Testsamp,type=response) since the load() created a variable 'fit' (same name as the one saved). HTH Peter On Mon, Oct 13,

Re: [R] Help with PredicABEL

2014-10-03 Thread Peter Langfelder
You are getting a p-value, namely p=0. It's just that, when taken literally, the p-values are wrong. I'm not familiar with predictABEL, but my guess is that the p-value is below 2e-16 or some such cutoff and gets printed as zero (the means seem to be about 10 standard deviations away from zero,

Re: [R] How to check to see if a variable is within a range of another variable

2014-10-01 Thread Peter Langfelder
On Wed, Oct 1, 2014 at 3:11 PM, Kate Ignatius kate.ignat...@gmail.com wrote: Is there an easy way to check whether a variable is within +/- 10% range of another variable in R? Yes, checkRange = function(A, B, range = 0.1) { A=B*(1-range) A=B*(1+range); } Test: A = c(67, 24, 40, 10, 70,

[R] as.Date woes

2014-08-20 Thread Peter Langfelder
Hi all, I have recently started working with Date objects and find the experience unsettling, to put it mildly. The help for as.Date says, in part: ## S3 method for class 'character' as.Date(x, format = , ...) x: An object to be converted. format: A character string. If

Re: [R] as.Date woes

2014-08-20 Thread Peter Langfelder
. G... Peter On Wed, Aug 20, 2014 at 11:56 AM, Peter Langfelder peter.langfel...@gmail.com wrote: Hi all, I have recently started working with Date objects and find the experience unsettling, to put it mildly. The help for as.Date says, in part: ## S3 method for class 'character

Re: [R] How Can SVD Reconstruct a Matrix

2014-08-14 Thread Peter Langfelder
On Wed, Aug 13, 2014 at 11:57 PM, Peter Brady subscripti...@simonplace.net wrote: Hi All, I've inherited some R code that I can't work out what they've done. It appears to work and give sort of reasonable answers, I'm just trying to work out why they've done what they have. I suspect that

Re: [R] big data?

2014-08-05 Thread Peter Langfelder
Have you tried read.csv.sql from package sqldf? Peter On Tue, Aug 5, 2014 at 10:20 AM, Spencer Graves spencer.gra...@structuremonitoring.com wrote: What tools do you like for working with tab delimited text files up to 1.5 GB (under Windows 7 with 8 GB RAM)? Standard tools for

Re: [R] Cutting hierarchical cluster tree at specific height fails

2014-07-15 Thread Peter Langfelder
Hi Johannes, you mentioned dynamicTreeCut - the dynamic hybrid method works fine on your data. Just supply the dissimilarity matrix as well: I use the function plotDendroAndColors from WGCNA to show the results; if you don't want to use WGCNA, just leave out the last call. library(WGCNA)

Re: [R] odd behavior of seq()

2014-07-03 Thread Peter Langfelder
Precision, precision, precision... z[2]-0.15 [1] 2.775558e-17 My solution: z - signif(seq(.05,.85,by=.1), 5) z[2] - 0.15 [1] 0 z[2]==0.15 [1] TRUE Peter On Thu, Jul 3, 2014 at 11:28 AM, Matthew Keller mckellerc...@gmail.com wrote: Hi all, A bit stumped here. z - seq(.05,.85,by=.1)

  1   2   3   4   5   >