similar to: apply vs. sapply

Displaying 20 results from an estimated 50000 matches similar to: "apply vs. sapply"

2002 Dec 27
2
RSvgDevice & sapply(plotmeans)
Hi, anybody know why this not works for several plots ? When i set onefile=T the plots are stacked one about another , onefile=F only the first plot is shown in AllbusMeansPlots.svg. [h2 is a data.frame] ......hist and sapply works for several plots nice with RSvgDevice ! Maybe setting the title after apply is a problem, but until yet i didn't found a better solution ? library(RSvgDevice)
2006 Mar 28
1
Help understanding behavior of apply vs sapply
Hi, I was surprised that apply and sapply don't return the same results in the example below. Can someone tell me what I'm missing? > zls <- function(x) character(0) > m <- matrix(0, nrow=2, ncol=2) > apply(m, 1, zls) character(0) > sapply(m, zls) [[1]] character(0) [[2]] character(0) [[3]] character(0) [[4]] character(0) > R.version _
2013 Apr 18
2
How to keep plot title same as column name using apply/sapply?
Dear list, I am trying to plot histogram of a 10 by 5 matrix by columns. What is a good way to paste the column names? dput(a) structure(c(0.891856482875103, 0.249593821948295, 0.0385066520473322, 0.109098868876336, 0.238035894186719, 0.971470380855763, 0.168018536530906, 0.941457062296419, -0.285381460315397, -0.0229335863796271, -20138.175683257, 28190.7238887329, 8521.44473371867,
2011 Oct 27
1
combining pairs plot with other plots in one output
I would like to combine multiple plots (one of which is a pairs plot) in one output display: While this works well: layout(matrix(c(1,2,3,3,3,3), ncol=2, byrow=T)) data <- matrix(rnorm(1000), ncol=10) boxplot(data) hist(data) plot(data) This doesn't: (because the pairs function seems to override the layout parameters?) layout(matrix(c(1,2,3,3,3,3), ncol=2, byrow=T)) data <-
2000 Mar 10
1
variable name to hist within apply?
Hello, After spending sometime trying to generate histograms of all the numeric variables in a data frame using a for loop, I realized I could use apply to create the histograms. This was one of those few moments when I `see' the alternative to looping. So, I can generate all the histograms with this command: apply(toblo.df[,-c(40,52)],2,hist) # 40 and 52 are ID's When I do this, the
2010 Feb 11
1
histogam plots
Hi all, I want to draw a histgram for each row of a matrix and compare them. However the plot I got does not have the same y range and x range, which makes it difficult to make the comparison. Is there a easy way to fix the x range and y range in a xy plot for several plots, instead of specifying them for each plot. The following is my code for generalizing the matrix and draw the histogram.
2011 Mar 13
1
problem with looping formula through table
Dear useRs, I am stuck with a piece of code and hope you could give me some pointers. My aim is to calculate the lm-regression coefficients of individual stocks against an index. I am interested in both the coefficient and the pval. While I could do this manually for a select hand full, I hope to scale this up say for 30+ stocks (DAX-30, FTSE-100 etc.) to eventually have a matrix of coefficients
2010 Dec 18
3
use of 'apply' for 'hist'
Hi all, ########################################## dof=c(1,2,4,8,16,32) Q5=matrix(rt(100,dof),100,6,T,dimnames=list(NULL,dof)) par(mfrow=c(2,6)) apply(Q5,2,hist) myf=function(x){ qqnorm(x);qqline(x) } apply(Q5,2,myf) ########################################## These looks ok. However, I would like to achieve more. Apart from using a loop, is there are fast way to 'add' the titles to be
2009 Jun 04
1
hist returning density larger than 1
The following code is giving me problems. I want to export densities of a distribution to a csv file. At the bottom of the code I use the hist function to generate the densities. But hist is returning values greater than 1. I don't understand, why. Any help you can supply is greatly appreciated. # Set word path dir<-"~/Research/MR Distribution Analysis/" setwd(dir)
1999 Feb 18
1
[Q] use of expression() in plot() vs. hist()
In plot() I can get greek symbols into text items without trouble. However, some of the same commands don't work as I would expect with hist(). See the example below. > plot(1:10, 2:11, xlab=expression(paste("scaled", rho))) ---- works as expected, ie. prints the greek rho > hist(c(0,0,0,0,4,5,6,6,6,8), xlab=expression(paste("scaled", rho))) Error: Object
2006 Jul 27
3
bug with rpois (PR#9106)
The R poisson random generator rpois appears to have a bug for theta 10 or larger. The sample mean of the pseudo variates is too small: sample mean approx theta - 0.5. I use Version 1.1.1 (August 15, 2000) Of R on a Dell OptiPlex computer with the Windows XP Professional operating system. Has this bug been fixed in later versions? (I found another reported rpois bug, but it appears to be
2013 Mar 27
1
Passing arguments between apply and l(s)apply functions vs. nested for loop
Hi R community, I have a question concerning passing arguments between apply and lapply? Or maybe, once my problem is explained, the question is really about how to best transform my nested for loops into list/matrix operations; I am just beginning this transformation away from nested for loops, so I beg of you to have some lenience regarding my ignorance. Part I: I used a set of nested for
2013 May 27
1
Plot histograms in a loop
Hi, Try either: set.seed(28) stats1<- as.data.frame(matrix(rnorm(5*10000),ncol=5)) pdf(paste("test",1,".pdf",sep="")) par(mfrow=c(2,1)) lst1<- lapply(names(stats1),function(i) {hist(stats1[,i],100,col="lightblue",main=paste0("Histogram of ",i),xlab=i );qqnorm(stats1[,i])}) dev.off() #or
2010 Apr 03
2
Export bug? Hist() vs. barchart().
Hi, If you want to export a single bar chart, this works: > png( "ET" ); > barchart( data[,"ET"] ) > dev.off() quartz_off_screen 2 But if you want to export a few of them, this does not: > factorCols <- c("MR","ET"); > sapply( factorCols, function(x) { + png( x ); + barchart( data[, x] ); + dev.off(); + } );
2002 Feb 07
2
FW: layout and piechart diameter problem (PR#1300)
Third try... > -----Original Message----- > From: Warnes, Gregory R > Sent: Tuesday, February 05, 2002 4:12 PM > To: 'R-bugs' > Subject: layout and piechart diameter problem > > > I've been using layout to create some graphics pages which include pie > charts. (NB: No piechart arguments please, the main chart on the page is > a proper bar chart
2010 Aug 10
3
sapply/lapply instead of loop
Using the input below, can I do something more elegant (and more efficient) than the loop also listed below to pad strings to a width of 5? The true matrix is about 300K rows and 31 columns. ####################### #INPUT ####################### > temp DX1 DX2 DX3 1 13761 8125 49178 2 63371 v75 22237 3 51745 77703 93500 4 64081 32826 v72 5 78477 43828 87645 >
2004 Sep 26
1
avoiding loops?
Hi, is it possible doing this "moving average" without a loop, because it is not really fast for dim(x) 300.000 50. I make some attempts with apply and sapply,but didn't get success until now. many thanks , christian ma <- function(x, FUN=mean, lag=5) { FUN=match.fun(FUN) n <- ncol(x) - lag frame <- matrix(0,nrow=nrow(x),ncol=n)
2004 Jun 07
2
strange apparently data-dependent crash with large data (PR#6955)
I'm consistently seeing R crash with a particular large data set. What's strange is that although the crash seems related to running out of memory, I'm unable to construct a pseudo-random data set of the same size that also causes the crash. Further adding to the strangeness is that the crash only happens if the dataset goes through a save()/load() cycle -- without that, the
2009 Jan 19
2
plotting arrows with different colors and varying head size
Dear list, I would like to plot arrows with different colors according to arrow length, and also (if possible) with head size proportional to arrow length. The idea is to make a quiver-like plot of matlab with wind speed data. So far, I´ve been able to use different colors, but I need to find a more efficient way to recode arrow length intervals into colors. On the contrary, I can't define
2010 Feb 16
1
difftimes; histogram; memory problems
Hi All: Let's say I have two dataframes (Condition1 and Condition2); each being on the order of 12,000 and 16,000 rows; 1 column. The entries contain dates. I'd like to calculate, for each possible pair of dates (that is: Condition1[1:10,000] and Condition2[1:10,000], the number of days difference between the dates in the pair. The result should be a matrix 12,000 by 16,000. Really,