Re: [R] sapply function and poisson distribution

2015-01-05 Thread peter dalgaard
On 05 Jan 2015, at 00:21 , Pete Brecknock peter.breckn...@bp.com wrote: n - c(1,2,3,4,5) lambda - c(0.1,0.8,1.2,2.2,4.2) mapply(function(x,y) rpois(x,y), n, lambda) Yes. I'd throw in a SIMPLIFY=FALSE to avoid getting results in a different format if n is constant (then again, sapply()

Re: [R] sapply function and poisson distribution

2015-01-04 Thread dimnik
thank you for your answer.Yes,that sounds right.I thought the same thing but the problem is how can i generalize the command for every vector of numbers not only for the specific example?not only for c(1,2),c(0.1,0.8). 2015-01-04 0:45 GMT+00:00 Pete Brecknock [via R]

Re: [R] sapply function and poisson distribution

2015-01-04 Thread Pete Brecknock
dimnik wrote thank you for your answer.Yes,that sounds right.I thought the same thing but the problem is how can i generalize the command for every vector of numbers not only for the specific example?not only for c(1,2),c(0.1,0.8). 2015-01-04 0:45 GMT+00:00 Pete Brecknock [via R]

Re: [R] sapply function and poisson distribution

2015-01-03 Thread Pete Brecknock
dimnik wrote i want to find a functionthattakes in two vectors of numbers thathave the same length.The output should be a listof vectors, where each vector is a sequence of randomly generated Poisson variableswhere the

Re: [R] sapply returning list instead of matrix

2014-02-03 Thread S Ellison
I can read the documentation, I see why it happens, but who in their right mind would design a function this way? I think you're possibly starting from the wrong perspective, or at least it might be useful to look at it from a different perspective. In many cases, such as simulations, lapply

Re: [R] sapply returning list instead of matrix

2014-02-02 Thread chris warth
Can I follow-up with what I've learned about my own myopia regarding sapply()? First, I appreciate all the feedback. After thinking about it for a while I realized R designers have often chosen to accommodate interactive usage, and in that context, sapply() returning different types makes

Re: [R] sapply returning list instead of matrix

2014-01-31 Thread Bert Gunter
As you ignored the posting guide and posted in HTML, your below didn't get through. So one can only guess that it has something to do with (see ?sapply) Simplification in sapply is only attempted if X has length greater than zero and if the return values from all elements of X are all of the same

Re: [R] sapply returning list instead of matrix

2014-01-31 Thread chris warth
Hey thanks for the helpful snark, Bert. To everyone else, I apologize for neglecting to actually include the examples. a - function(i) { list(1) } b - function(i) { list(1,2) } ll - sapply(seq(3), a, simplfy=list) mm - sapply(seq(3), b) class(ll) class(mm) class(ll) [1] list class(mm) [1]

Re: [R] sapply returning list instead of matrix

2014-01-31 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of chris warth Sent: Friday, January 31, 2014 2:22 PM To: r-help@r-project.org Subject: Re: [R] sapply returning list instead of matrix Hey thanks for the helpful snark, Bert

Re: [R] sapply returning list instead of matrix

2014-01-31 Thread Jeff Newmiller
Pot, meet kettle. You claim to be able to read documentation, yet you don't reference knowledge gained or clarity lost from such activity in your question. I think this is a case of inertia of history that we all have to live with at this point. If you thoroughly read the documentation for

Re: [R] SAPPLY function for COLUMN NULL

2013-05-26 Thread arun
colnames(dd) #[1] col1 colb null_vector- colnames(dd) sapply(null_vector,makeNull,dd) # col1 colb #[1,]   NA    4 #[2,]    2   NA #[3,]    3    2 #[4,]    4   NA #[5,]    1    4 #[6,]   NA    5 #[7,]    1    6 A.K. I am trying to make a column value in a dataframe = NA if there is a 0 or

Re: [R] sapply error produced by grid search

2013-05-16 Thread Berend Hasselman
On 16-05-2013, at 17:31, Patel, Shreena s.pate...@lancaster.ac.uk wrote: Dear R User, I'm trying to perform a grid-search for the ML estimator of the Box-Cox parameter for a linear mixed model. However using sapply to perform the grid search returns an error message. Here's a small

Re: [R] sapply and matrix command

2012-08-09 Thread R. Michael Weylandt
On Wed, Aug 8, 2012 at 10:37 AM, alijk1989 [via R] ml-node+s789695n4639622...@n4.nabble.com wrote: Hi Michael, Thanks for your response. Here is a simple example of what I am trying to do: w=rep(0.02,10) Q=rep(0.02,10) rho=matrix(0.5,nrow=10,ncol=10) m=10 LGD=0.45 M1=sum(sapply(1:m,

Re: [R] sapply and matrix command

2012-08-08 Thread alijk1989 [via R]
Hi, I have made some progress speeding up my code. This is what I have at the moment: M1=sum(sapply(1:m, function(k){sum(sapply(1:m,function(j){w[k]*w[j]*LGD^2 (pmnorm(c(qnorm(Q[k]),qnorm(Q[j])),c(0,0),equicorr(2,rho[k,j]))-Q[k]*Q[j])}))})) I tried setting up a function as so: f1 -

Re: [R] sapply and matrix command

2012-08-08 Thread R. Michael Weylandt
On Wed, Aug 8, 2012 at 9:17 AM, alijk1989 [via R] ml-node+s789695n4639595...@n4.nabble.com wrote: Hi, I have made some progress speeding up my code. This is what I have at the moment: M1=sum(sapply(1:m, function(k){sum(sapply(1:m,function(j){w[k]*w[j]*LGD^2

Re: [R] sapply and matrix command

2012-08-08 Thread alijk1989 [via R]
Hi Michael, Thanks for your response. Here is a simple example of what I am trying to do: w=rep(0.02,10) Q=rep(0.02,10) rho=matrix(0.5,nrow=10,ncol=10) m=10 LGD=0.45 M1=sum(sapply(1:m,

Re: [R] sapply() and by()

2012-08-06 Thread Jean V Adams
Dominic, It's great that you provided some example data, but a much smaller data frame would have sufficed. For example, 10 randomly selected rows from your data ... LF - structure(list(Serra.da.Foladoira = c(27.335652173913, 25.4632608695652, 24.464652173913, 22.550652173913,

Re: [R] sapply() and by()

2012-08-06 Thread David Winsemius
On Aug 6, 2012, at 7:34 AM, Dominic Roye wrote: Hello everyone, I have a dataset with 5 colums (4 colums with thresholds of weather stations and one with month - data of 5 years). Now I would like to calculate the average for each month. I tried this unsuccessfully: lf.med -

Re: [R] sapply and matrix command

2012-08-04 Thread alijk1989 [via R]
Thanks again for the help looks like this will be useful for what I'm doing. Is there any way to use combn to return combinations of values with themselves: e.g. combn(1:3,2) [,1] [,2] [,3] [,4] [,5] [,6] [1,]111 2 2 3 [2,]1 232 3 3

Re: [R] sapply and matrix command

2012-08-04 Thread R. Michael Weylandt michael.weyla...@gmail.com
Take a look at ?expand.grid Michael On Aug 4, 2012, at 5:03 PM, alijk1989 [via R] ml-node+s789695n463919...@n4.nabble.com wrote: Thanks again for the help looks like this will be useful for what I'm doing. Is there any way to use combn to return combinations of values with themselves:

Re: [R] sapply and matrix command

2012-08-01 Thread arun kirshna [via R]
HI, You can also try this: d-1:25 A-sample(combn(20:30,2)) B-sample(combn(20:30,2)) lapply(d,function(x) matrix(c(1,A[x],B[x],1),2,2)) [[1]] [,1] [,2] [1,]1 23 [2,] 271 [[2]] [,1] [,2] [1,]1 21 [2,] 211 [[3]] [,1] [,2] [1,]1 29 [2,] 231 [[4]]

Re: [R] sapply question

2012-07-11 Thread jim holtman
Go back and reread the section about the scoping of variables and that functions do not have side effects; they only return values. You are changinga local copy of df1 within the function which is returning the changed values to df3. On Wed, Jul 11, 2012 at 7:36 PM, Charles Stangor

Re: [R] sapply help

2012-02-04 Thread Milan Bouchet-Valat
Le vendredi 03 février 2012 à 18:51 +, William Dunlap a écrit : Instead of colSums(t(aMatrix)), why not the more direct rowSums(aMatrix)? Because I felt it was more didactic. The question was about counting occurrences per column, so using rowSums() could be a little confusing without an

Re: [R] sapply help

2012-02-03 Thread Ernest Adrogué
3-02-2012, 08:37 (-0800); Filoche escriu: Hi every one. I'm learning how to use sapply (and other function of this family). Here's what I'm trying to do. I have a vector of lets say 5 elements. I also have a matrix of nX5. I would like to know how many element by column are inferior to

Re: [R] sapply help

2012-02-03 Thread Milan Bouchet-Valat
Le vendredi 03 février 2012 à 18:27 +0100, Ernest Adrogué a écrit : 3-02-2012, 08:37 (-0800); Filoche escriu: Hi every one. I'm learning how to use sapply (and other function of this family). Here's what I'm trying to do. I have a vector of lets say 5 elements. I also have a

Re: [R] sapply help

2012-02-03 Thread William Dunlap
-help-boun...@r-project.org] On Behalf Of Milan Bouchet- Valat Sent: Friday, February 03, 2012 10:17 AM To: Ernest Adrogué Cc: r-help@r-project.org Subject: Re: [R] sapply help Le vendredi 03 février 2012 à 18:27 +0100, Ernest Adrogué a écrit : 3-02-2012, 08:37 (-0800); Filoche escriu

Re: [R] sapply help

2012-02-03 Thread Filoche
Thank you sire. You explained it very well. This give ma a good point to start using sapply more frequently. Cordially, Phil -- View this message in context: http://r.789695.n4.nabble.com/sapply-help-tp4355092p4355376.html Sent from the R help mailing list archive at Nabble.com.

Re: [R] sapply Call Returning the condition has length 1 Error

2011-12-27 Thread R. Michael Weylandt
You are right that the problem is that DummyFunc isn't vectorized. R looks for a single logical value in an if statement but x0 gives it a whole vector's worth -- as the warning indicates, it only uses the first and pushes the whole vector through the loop in the return(-x) branch, which explains

Re: [R] sapply Call Returning the condition has length 1 Error

2011-12-27 Thread John Fox
Dear Alex, -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Alex Zhang Sent: December-27-11 2:14 PM To: r-help@r-project.org Subject: [R] sapply Call Returning the condition has length 1 Error Dear all, Happy new

Re: [R] sapply Call Returning the condition has length 1 Error

2011-12-27 Thread Alex Zhang
Subject: RE: [R] sapply Call Returning the condition has length 1 Error Dear Alex, -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- project.org] On Behalf Of Alex Zhang Sent: December-27-11 2:14 PM To: r-help@r-project.org Subject: [R] sapply Call

Re: [R] sapply Call Returning the condition has length 1 Error

2011-12-27 Thread jim holtman
...@mcmaster.ca To: 'Alex Zhang' alex.zh...@ymail.com Cc: r-help@r-project.org Sent: Tuesday, December 27, 2011 3:10 PM Subject: RE: [R] sapply Call Returning the condition has length 1 Error Dear Alex, -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-bounces@r

Re: [R] sapply Call Returning the condition has length 1 Error

2011-12-27 Thread John Fox
Dear Alex, -Original Message- From: Alex Zhang [mailto:alex.zh...@ymail.com] Sent: December-27-11 3:34 PM To: John Fox Cc: r-help@r-project.org Subject: Re: [R] sapply Call Returning the condition has length 1 Error John, Thanks for the pointers. The DummyFunc is just

Re: [R] sapply Call Returning the condition has length 1 Error

2011-12-27 Thread Alex Zhang
...@mcmaster.ca To: 'Alex Zhang' alex.zh...@ymail.com Cc: r-help@r-project.org Sent: Tuesday, December 27, 2011 4:06 PM Subject: RE: [R] sapply Call Returning the condition has length 1 Error Dear Alex, -Original Message- From: Alex Zhang [mailto:alex.zh...@ymail.com] Sent: December-27

Re: [R] sapply Call Returning the condition has length 1 Error

2011-12-27 Thread Jeff Newmiller
!� From: John Fox j...@mcmaster.ca To: 'Alex Zhang' alex.zh...@ymail.com Cc: r-help@r-project.org Sent: Tuesday, December 27, 2011 4:06 PM Subject: RE: [R] sapply Call Returning the condition has length 1 Error Dear Alex, -Original Message- From: Alex Zhang [mailto:alex.zh...@ymail.com

Re: [R] sapply Call Returning the condition has length 1 Error

2011-12-27 Thread Alex Zhang
' alex.zh...@ymail.com Cc: r-help@r-project.org Sent: Tuesday, December 27, 2011 4:06 PM Subject: RE: [R] sapply Call Returning the condition has length 1 Error Dear Alex, -Original Message- From: Alex Zhang [mailto:alex.zh...@ymail.com] Sent: December-27-11 3:34 PM To: John Fox

Re: [R] sapply Call Returning the condition has length 1 Error

2011-12-27 Thread R. Michael Weylandt
' alex.zh...@ymail.com Cc: r-help@r-project.org Sent: Tuesday, December 27, 2011 4:06 PM Subject: RE: [R] sapply Call Returning the condition has length 1 Error Dear Alex, -Original Message- From: Alex Zhang [mailto:alex.zh...@ymail.com] Sent: December-27-11 3:34 PM To: John Fox Cc

Re: [R] sapply Call Returning the condition has length 1 Error

2011-12-27 Thread Alex Zhang
Zhang alex.zh...@ymail.com Cc: John Fox j...@mcmaster.ca; r-help@r-project.org r-help@r-project.org Sent: Tuesday, December 27, 2011 6:59 PM Subject: Re: [R] sapply Call Returning the condition has length 1 Error Your puzzle comes from a collision of two somewhat subtle facts that i) sapply

Re: [R] sapply(pred,cor,y=resp)

2011-10-09 Thread Joshua Wiley
Hi, It is probably more confusing with several steps combined, but you are correct that it is because there are NAs. It is fairly common for R functions to return NA if there are any NA values unless you explicitly set an argument on what to do with missing values. A quick look at ?cor clearly

Re: [R] sapply to bind columns, with repeat?

2011-08-13 Thread Katrina Bennett
Hi Weidong Gu, This works! For my clarity, and so I can repeat this process if need be: The 'mat' generates a matrix using whatever is supplied to x (i.e. coop.dat) using the columns from position 9:length(x) of 6 columns (by row). The 'rem.col' generates a matrix of the first 1:8 columns of 8

Re: [R] sapply to bind columns, with repeat?

2011-08-12 Thread Weidong Gu
Katrina, try this. reorg-function(x){ mat-matrix(x[9:length(x)],ncol=6,byrow=T) rem.col-matrix(rep(x[1:8],nrow(mat)),byrow=T,ncol=8) return(data.frame(cbind(rem.col,mat))) } co-do.call('rbind',apply(coop.dat,1,function(x) reorg(x))) You may need to tweak a bit to fit exactly what you want.

Re: [R] sapply to bind columns, with repeat?

2011-08-12 Thread Weidong Gu
On Fri, Aug 12, 2011 at 5:08 PM, Katrina Bennett kebenn...@alaska.edu wrote: Hi Weidong Gu, This works! For my clarity, and so I can repeat this process if need be: The 'mat' generates a matrix using whatever is supplied to x (i.e. coop.dat) using the columns from position 9:length(x) of 6

Re: [R] sapply( ) a loop function

2011-08-11 Thread Daniel Malter
I am not sure what purpose the while loop has. However, the main problem seems to be that you need to put: i-sample(1:(n-40),1) #This sample from 1 to n-40 rather than i-sample(1:n-40,1) #this samples one 1:n and then subtracts 40 Otherwise, you may get negative index values Best, Daniel

Re: [R] sapply( ) a loop function

2011-08-11 Thread Dennis Murphy
Hi: samp_func() doesn't return anything. Either (1) type test as the last line of the function body or (2) don't assign the last sum to an object. HTH, Dennis On Thu, Aug 11, 2011 at 1:59 PM, Sean Bignami bignam...@gmail.com wrote: Hello R-universe... I am having trouble writing a function

Re: [R] sapply( ) a loop function

2011-08-11 Thread R. Michael Weylandt
The previous two posters basically covered everything, but since I'm on the train with not too much to do, here's a more detailed response building on what they said. The following code is shovel-ready and can be pasted directly to your command line if you have your main data frame called d

Re: [R] SAPPLY function XXXX

2011-05-04 Thread Erik Iverson
Dan, I am attempting to write a function to count the number of non-missing values of each column in a data frame using the sapply function. I have the following code which is receiving the error message below. n.valid-sapply(data1,sum(!is.na)) Error in !is.na : invalid argument type

Re: [R] SAPPLY function XXXX

2011-05-04 Thread Erik Iverson
Ultimately, I would like for this to be 1 conponent in a larger function that will produce PROC CONTENTS style output. Something like... data1.contents-data.frame(Variable=names(data1), Class=sapply(data1,class), n.valid=sapply(data1,sum(!is.na)), n.miss=sapply(data1,sum(is.na)))

Re: [R] SAPPLY function XXXX

2011-05-04 Thread Dan Abner
Perfect Erik! Thank you! On Wed, May 4, 2011 at 4:22 PM, Erik Iverson er...@ccbr.umn.edu wrote: Dan, I am attempting to write a function to count the number of non-missing values of each column in a data frame using the sapply function. I have the following code which is receiving the

Re: [R] SAPPLY function XXXX

2011-05-04 Thread Petr PIKAL
Hi r-help-boun...@r-project.org napsal dne 04.05.2011 22:26:59: Erik Iverson er...@ccbr.umn.edu Odeslal: r-help-boun...@r-project.org 04.05.2011 22:26 Komu Dan Abner dan.abne...@gmail.com Ultimately, I would like for this to be 1 conponent in a larger function that will

Re: [R] Sapply for descriptive statistics

2011-03-09 Thread David Winsemius
Sent from my iPhone On Mar 9, 2011, at 5:59 PM, Tomii dioge...@gmail.com wrote: I try to calculate descriptive statistics for one of the variables in the data frame, however command sapply calculates these statistics for every value of the variable separately. How to make it calculate range

Re: [R] Sapply for descriptive statistics

2011-03-09 Thread Dennis Murphy
Hi: Perhaps something like this? m - matrix(rnorm(100, m = 10, s = 2), ncol = 5) colnames(m) - paste('V', 1:5, sep = '') # Summary function: summs - function(x) c(mean = mean(x), sd = sd(x), range = diff(range(x))) # Apply to columns of m and transpose the result: t(apply(m, 2, summs)) For

Re: [R] Sapply for descriptive statistics

2011-03-09 Thread David Winsemius
Sent from my iPhone On Mar 9, 2011, at 6:13 PM, David Winsemius dwinsem...@comcast.net wrote: Sent from my iPhone On Mar 9, 2011, at 5:59 PM, Tomii dioge...@gmail.com wrote: I try to calculate descriptive statistics for one of the variables in the data frame, however command sapply

Re: [R] sapply puzzlement

2011-01-27 Thread David A. Johnston
sapply(z, function(row) ...) does not actually grab a row at a time out of 'z'. It grabs a column (because 'z' is a data.frame) You may want: t(apply(z, 1, function(row) row - means)) or: t(t(z) - means) Hope that helps, -David Johnston -- View this message in context:

Re: [R] sapply puzzlement

2011-01-27 Thread David Winsemius
On Jan 27, 2011, at 7:16 PM, Ernest Adrogué i Calveras wrote: Hi, I have this data.frame with two variables in it, z V1 V2 1 10 8 2 NA 18 3 9 7 4 3 NA 5 NA 10 6 11 12 7 13 9 8 12 11 and a vector of means, means - apply(z, 2, function (col) mean(na.omit(col))) means V1

Re: [R] sapply puzzlement

2011-01-27 Thread Pete Brecknock
In addition to what has already been suggested you could use .. mapply(function(x,y) x-y, z,means) which returns V1 V2 [1,] 0.333 -2.7142857 [2,] NA 7.2857143 [3,] -0.667 -3.7142857 [4,] -6.667 NA [5,] NA -0.7142857 [6,]

Re: [R] sapply puzzlement

2011-01-27 Thread Dario Strbenac
R works by going down the columns. If you make the rows into columns, it then does what you want. You just have to make the columns back into rows to get the original shape of your matrix. So the code in one line is : t(t(z) - means) Original message Date: Fri, 28 Jan 2011 01:16:45

Re: [R] SApply versus for loop for list of data.frames

2010-10-11 Thread David Winsemius
On Oct 12, 2010, at 12:16 AM, rivercode wrote: Hi, I am trying to find the total number of rows for a list of data.frames and want to know if there is a better way than using a loop like: df = { list of data.frame with varying number of rows...each one has a column called COL } r = 0

Re: [R] SApply versus for loop for list of data.frames

2010-10-11 Thread David Winsemius
On Oct 12, 2010, at 12:33 AM, David Winsemius wrote: On Oct 12, 2010, at 12:16 AM, rivercode wrote: Hi, I am trying to find the total number of rows for a list of data.frames and want to know if there is a better way than using a loop like: df = { list of data.frame with varying

Re: [R] sapply/lapply instead of loop

2010-08-10 Thread jim holtman
will this do what you want: newTemp[] - lapply(newTemp, function(.col){ + # convert to character and pad to 5 space + sprintf(%5s, as.character(.col)) + }) str(newTemp) 'data.frame': 5 obs. of 3 variables: $ DX1: chr 13761 63371 51745 64081 ... $ DX2: chr 8125 v75 77703 32826

Re: [R] sapply/lapply instead of loop

2010-08-10 Thread Henrique Dallazuanna
Try this: formatC(as.matrix(temp)) On Tue, Aug 10, 2010 at 3:55 PM, GL pfl...@shands.ufl.edu wrote: 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.

Re: [R] sapply/lapply instead of loop

2010-08-10 Thread GL
Both of those approaches seem to return ( v75) instead of (v75 ). -- View this message in context: http://r.789695.n4.nabble.com/sapply-lapply-instead-of-loop-tp2320265p2320305.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] sapply/lapply instead of loop

2010-08-10 Thread Henrique Dallazuanna
So try: format(as.matrix(temp)) On Tue, Aug 10, 2010 at 4:13 PM, GL pfl...@shands.ufl.edu wrote: Both of those approaches seem to return ( v75) instead of (v75 ). -- View this message in context: http://r.789695.n4.nabble.com/sapply-lapply-instead-of-loop-tp2320265p2320305.html Sent

Re: [R] sapply/lapply instead of loop

2010-08-10 Thread GL
That works great, and is ever so much simpler. Thanks much! -- View this message in context: http://r.789695.n4.nabble.com/sapply-lapply-instead-of-loop-tp2320265p2320317.html Sent from the R help mailing list archive at Nabble.com. __

Re: [R] sapply or apply

2010-06-17 Thread Joshua Wiley
Hello Roslina, Maybe it is just me, but I have difficulty picking apart what you are trying to do because, the data have the same names as the arguments in your functions, and when you create the function term(), you have two sets of arguments (for term() and for gam_sum() ) that have the same

Re: [R] sapply code

2010-05-16 Thread Henrique Dallazuanna
Try this: 1 + (1 / log(length(lambda_cor))) * sum((l - lambda_cor / length(lambda_cor)) * log(l)) On Sun, May 16, 2010 at 10:43 PM, Roslina Zakaria zrosl...@yahoo.comwrote: Hi r-users, I have this code here, but I just wonder how do I use 'sapply' to make it more efficient lamda_cor -

Re: [R] sapply, lattice functions

2010-03-21 Thread Santosh
Dear R-gurus.. How do I implement the following: a) Overlay frequency(instead of density) with line of density plot, vertical lines of confidence intervals and reference levels? b) Control the breaks (using nint?), order of the panel, and the layout, place units for each conditioning variable?

Re: [R] sapply, lattice functions

2010-03-20 Thread Dieter Menne
Sundar Dorai-Raj-2 wrote: Or perhaps more clearly, histogram(~a1 + b1 + c1, data = aa, outer = TRUE) Why outer=TRUE? Looks same for me without: Dieter library(lattice) aa - data.frame(a1=rnorm(20),b1=rnorm(20,0.8),c1=rnorm(20,0.5)) histogram(~a1 + b1 + c1, data = aa) -- View this

Re: [R] sapply, lattice functions

2010-03-20 Thread Sundar Dorai-Raj
You're right. It's necessary for xyplot though to prevent grouping. On Mar 20, 2010 10:43 AM, Dieter Menne dieter.me...@menne-biomed.de wrote: Sundar Dorai-Raj-2 wrote: Or perhaps more clearly, histogram(~a1 + b1 + c1, data = aa, o... Why outer=TRUE? Looks same for me without: Dieter

Re: [R] sapply, lattice functions

2010-03-19 Thread Gabor Grothendieck
Try this: junk - sapply(aa,function(x) print(histogram(x,breaks=NULL))) or, shorter: for(a in aa) print(histogram(a, breaks = NULL) On Fri, Mar 19, 2010 at 5:44 PM, Santosh santosh2...@gmail.com wrote: Dear R-gurus aa - data.frame(a1=rnorm(20),b1=rnorm(20,0.8),c1=rnorm(20,0.5))

Re: [R] sapply, lattice functions

2010-03-19 Thread Santosh
Thanks for your response. how do I print them in an ordered manner, akin to using print(px,split=c(2,2,1,1),more=T)) or par(mfrow=c(x,y))? -Santosh On Fri, Mar 19, 2010 at 2:58 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try this: junk - sapply(aa,function(x)

Re: [R] sapply, lattice functions

2010-03-19 Thread Gabor Grothendieck
Try this: histogram(~ values | ind, stack(aa)) On Fri, Mar 19, 2010 at 5:44 PM, Santosh santosh2...@gmail.com wrote: Dear R-gurus aa - data.frame(a1=rnorm(20),b1=rnorm(20,0.8),c1=rnorm(20,0.5)) sapply(aa,function(x) histogram(x,breaks=NULL)) or px - sapply(aa,function(x)

Re: [R] sapply, lattice functions

2010-03-19 Thread Sundar Dorai-Raj
Or perhaps more clearly, histogram(~a1 + b1 + c1, data = aa, outer = TRUE) --sundar On Fri, Mar 19, 2010 at 3:50 PM, Gabor Grothendieck ggrothendi...@gmail.com wrote: Try this: histogram(~ values | ind, stack(aa)) On Fri, Mar 19, 2010 at 5:44 PM, Santosh santosh2...@gmail.com wrote:

Re: [R] Sapply

2009-08-30 Thread Gabor Grothendieck
Try this: data$score - ave(data$score, data$group, FUN = prop.table) On Sun, Aug 30, 2009 at 6:08 PM, Noah Silvermann...@smartmediacorp.com wrote: Hi, I need a bit of guidance with the sapply function.  I've read the help page, but am still a bit unsure how to use it. I have a large data

Re: [R] Sapply

2009-08-30 Thread Duncan Murdoch
On 30/08/2009 6:08 PM, Noah Silverman wrote: Hi, I need a bit of guidance with the sapply function. I've read the help page, but am still a bit unsure how to use it. I have a large data frame with about 100 columns and 30,000 rows. One of the columns is group of which there are about

Re: [R] Sapply

2009-08-30 Thread hadley wickham
On Sun, Aug 30, 2009 at 5:08 PM, Noah Silvermann...@smartmediacorp.com wrote: Hi, I need a bit of guidance with the sapply function.  I've read the help page, but am still a bit unsure how to use it. I have a large data frame with about 100 columns and 30,000 rows.  One of the columns is

Re: [R] sapply() related query

2009-06-17 Thread Marc Schwartz
On Jun 17, 2009, at 10:06 AM, Girish A.R. wrote: Hi folks, I'm trying to consolidate the outputs (of anova() and lrm()) from multiple runs of single-variable logistic regression. Here's how the output looks:

Re: [R] sapply() related query

2009-06-17 Thread Girish A.R.
Thanks, Marc! This is what I was looking for. best, -Girish PS: Also appreciate your concern about this being a part of a variable selection process. On Jun 17, 9:01 pm, Marc Schwartz marc_schwa...@me.com wrote: On Jun 17, 2009, at 10:06 AM, Girish A.R. wrote: Hi folks, I'm trying to

Re: [R] sapply

2009-02-08 Thread Sundar Dorai-Raj
I'm not sure what you really want, so perhaps a simple example would help (i.e. what a sample of the input looks like and what the output you need looks like). My guess would be sapply(df, diff) but again, I'm not sure. --sundar On Sun, Feb 8, 2009 at 4:24 PM, glenn

Re: [R] sapply

2009-02-08 Thread glenn
Bullseye ! thanks a lot Sundar -Original Message- From: Sundar Dorai-Raj [mailto:sdorai...@gmail.com] Sent: 09 February 2009 00:31 To: glenn Cc: r-help@r-project.org Subject: Re: [R] sapply I'm not sure what you really want, so perhaps a simple example would help (i.e. what a sample

Re: [R] sapply and median, possible or not ?

2008-11-07 Thread Ptit_Bleu
Unfortunately, I have the same error message. lapply(rowsplit, function(x)mean(x[,sapply(x, is.numeric)])) works but not with median. Strange, isn't it? Any other idea? Thanks in advance, Ptit Bleu. Henrique Dallazuanna wrote: Try this: lapply(l, function(x)median(x[,sapply(x,

Re: [R] sapply and median, possible or not ?

2008-11-07 Thread Henrique Dallazuanna
You can provide a example of your data? On Fri, Nov 7, 2008 at 9:14 AM, Ptit_Bleu [EMAIL PROTECTED] wrote: Unfortunately, I have the same error message. lapply(rowsplit, function(x)mean(x[,sapply(x, is.numeric)])) works but not with median. Strange, isn't it? Any other idea? Thanks in

Re: [R] sapply and median, possible or not ?

2008-11-07 Thread Keith Jewell
I haven't looked at the detail, but I guess the answer is that mean works on a data frame while median doesn't. ?mean snip For a data frame, a named vector with the appropriate method being applied column by column. - I guess to use median you'll need nested '[l/s]apply's, the