Displaying 20 results from an estimated 9000 matches similar to: "Calculating rowMeans from different columns in each row?"
2018 Feb 20
5
Take the maximum of every 12 columns
Dear all,
I have monthly data in wide format, I am only providing data (at the bottom
of the email) for the first 24 columns but I have 2880 columns in total.
I would like to take max of every 12 columns. I have taken the mean of
every 12 columns with the following code:
byapply <- function(x, by, fun, ...)
{
# Create index list
if (length(by) == 1)
{
nc <- ncol(x)
2011 Dec 19
2
Summing x1 to x6
Suppose I have the following:
x1<-as.vector(rnorm(10))
x2<-as.vector(rnorm(10))
x3<-as.vector(rnorm(10))
x4<-as.vector(rnorm(10))
x5<-as.vector(rnorm(10))
x6<-as.vector(rnorm(10))
x7<-as.vector(rnorm(10))
x8<-as.vector(rnorm(10))
x9<-as.vector(rnorm(10))
x10<-as.vector(rnorm(10))
I would like the mean of x1 to x6 for each vector position. I would do
something else
2018 Feb 20
0
Take the maximum of every 12 columns
Hi Milu,
byapply(df, 12, function(x) apply(x, 1, max))
You might also be interested in the matrixStats package.
Best,
Ista
On Tue, Feb 20, 2018 at 9:55 AM, Miluji Sb <milujisb at gmail.com> wrote:
> Dear all,
>
> I have monthly data in wide format, I am only providing data (at the bottom
> of the email) for the first 24 columns but I have 2880 columns in total.
>
> I
2018 Feb 20
3
Take the maximum of every 12 columns
This is what I was looking for. Thank you everyone!
Sincerely,
Milu
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
Mail
priva di virus. www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail>
2018 Feb 20
0
Take the maximum of every 12 columns
Ista, et. al: efficiency?
(Note: I needed to correct my previous post: do.call() is required for
pmax() over the data frame)
> x <- data.frame(matrix(runif(12e6), ncol=12))
> system.time(r1 <- do.call(pmax,x))
user system elapsed
0.049 0.000 0.049
> identical(r1,r2)
[1] FALSE
> system.time(r2 <- apply(x,1,max))
user system elapsed
2.162 0.045 2.207
##
2018 Feb 20
0
Take the maximum of every 12 columns
The maximum over twelve columns is the maximum of the twelve maxima of
each of the columns.
single_col_max <- apply(x, 2, max)
twelve_col_max <- apply(
matrix(single_col_max, nrow = 12),
2,
max
)
ir. Thierry Onkelinx
Statisticus / Statistician
Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE
AND FOREST
Team Biometrie
2005 Oct 05
1
Ad: Re: R crashes for large formulas in lm() (PR#8180)
Dette er en melding med flere deler i MIME-format.
--=_alternative 004613C000257091_=
Content-Type: text/plain; charset="US-ASCII"
And some more informastion I forgot.
R does not crash if I write out the formula:
set.seed(123)
x1 <- runif(1000)
x2 <- runif(1000)
x3 <- runif(1000)
x4 <- runif(1000)
x5 <- runif(1000)
x6 <- runif(1000)
x7 <- runif(1000)
x8 <-
2013 Apr 13
1
how to add a row vector in a dataframe
Hi,
Using S=1000
and
simdata <- replicate(S, generate(3000))
#If you want both "m1" and "m0" #here the missing values are 0
res1<-sapply(seq_len(ncol(simdata.psm1)),function(i) {x1<-merge(simdata.psm0[,i],simdata.psm1[,i],all=TRUE); x1[is.na(x1)]<-0; x1})
res1[,997:1000]
#????? [,1]???????? [,2]???????? [,3]???????? [,4]???????
#x1??? Numeric,3000 Numeric,3000
2018 Feb 20
2
Take the maximum of every 12 columns
Don't do this (sorry Thierry)! max() already does this -- see ?max
> x <- data.frame(a =rnorm(10), b = rnorm(10))
> max(x)
[1] 1.799644
> max(sapply(x,max))
[1] 1.799644
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic
2008 Dec 22
1
sem package fails when no of factors increase from 3 to 4
#### I checked through every 3 factor * 3 loading case.
#### While, 4 factor * 3 loading failed.
#### the data is 6 factor * 3 loading
require(sem);
cor18<-read.moments();
1
.68 1
.60 .58 1
.01 .10 .07 1
.12 .04 .06 .29 1
.06 .06 .01 .35 .24 1
.09 .13 .10 .05 .03 .07 1
.04 .08 .16 .10 .12 .06 .25 1
.06 .09 .02 .02 .09 .16 .29 .36 1
.23 .26 .19 .05 .04 .04 .08 .09 .09 1
.11 .13 .12 .03 .05 .03
2010 Apr 19
2
How to pass a list of parameters into a function
Does anyone know how to pass a list of parameters into a function?
for example:
somefun=function(x1,x2,x3,x4,x5,x6,x7,x8,x9){
ans=x1+x2+x3+x4+x5+x6+x7+x8+x9
return(ans)
}
somefun(1,2,3,4,5,6,7,8,9)
# I would like this to work:
temp=c(x3=3,x4=4,x5=5,x6=6,x7=7,x8=8,x9=9)
somefun(x1=1,x2=2,temp)
# OR I would like this to work:
temp=list(x3=3,x4=4,x5=5,x6=6,x7=7,x8=8,x9=9)
2017 Aug 22
1
boot.stepAIC fails with computed formula
SImplify your call to lm using the "." argument instead of
manipulating formulas.
> strt <- lm(y1 ~ ., data = dat)
and you do not need to explicitly specify the "1+" on the rhs for lm, so
> frm2<-as.formula(paste(trg," ~ ", paste(xvars,collapse = "+")))
works fine, too.
Anyway, doing this gives (but see end of output)"
bst <-
2018 Feb 20
2
Take the maximum of every 12 columns
On Tue, Feb 20, 2018 at 11:58 AM, Bert Gunter <bgunter.4567 at gmail.com>
wrote:
> Ista, et. al: efficiency?
> (Note: I needed to correct my previous post: do.call() is required for
> pmax() over the data frame)
>
> > x <- data.frame(matrix(runif(12e6), ncol=12))
>
> > system.time(r1 <- do.call(pmax,x))
> user system elapsed
> 0.049 0.000
2006 Aug 31
3
what's wrong with my simulation programs on logistic regression
Dear friends,
I'm doing a simulation on logistic regression model, but the programs can't
work well,please help me to correct it and give some suggestions.
My programs:
data<-matrix(rnorm(400),ncol=8) #sample size is 50
data<-data.frame(data)
names(data)<-c(paste("x",1:8,sep="")) #8 independent variables,x1-x8;
#logistic regression model is
2013 May 29
3
bootstrap
Hi,
You might need to check library(boot).? I have never used that before.? So, I can't comment much.? It is better to post on R-help list.? I had seen your postings on Nabble in the past.? Unfortunately those postings were not accepted in R-help.? You have to directly post at ? r-help at r-project.org after registering at:
https://stat.ethz.ch/mailman/listinfo/r-help
?
2018 Feb 20
0
Take the maximum of every 12 columns
Thank you for your kind replies. Maybe I was not clear with my question (I
apologize) or I did not understand...
I would like to take the max for X0...X11 and X12...X24 in my dataset. When
I use pmax with the function byapply as in
byapply(df, 12, pmax)
I get back a list which I cannot convert to a dataframe. Am I missing
something? Thanks again!
Sincerely,
Milu
2006 Aug 20
2
how to the p-values or t-values from the lm's results
Dear friends,
After running the lm() model, we can get summary resluts like the
following:
Coefficients:
Estimate Std. Error t value Pr(>|t|)
x1 0.11562 0.10994 1.052 0.2957
x2 -0.13879 0.09674 -1.435 0.1548
x3 0.01051 0.09862 0.107 0.9153
x4 0.14183 0.08471 1.674 0.0975 .
x5 0.18995 0.10482 1.812 0.0732 .
x6 0.24832 0.10059 2.469 0.0154 *
x7
2017 Aug 22
1
boot.stepAIC fails with computed formula
Failed? What was the error message?
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Tue, Aug 22, 2017 at 8:17 AM, Stephen O'hagan
<SOhagan at manchester.ac.uk> wrote:
> I'm trying to use boot.stepAIC for
2017 Aug 22
0
boot.stepAIC fails with computed formula
The error is "the model fit failed in 50 bootstrap samples
Error: non-character argument"
Cheers,
SOH.
On 22/08/2017 17:52, Bert Gunter wrote:
> Failed? What was the error message?
>
> Cheers,
>
> Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka
2018 Feb 20
0
Take the maximum of every 12 columns
It looks like OP uses a data.frame, so in order to use matrixStats
(I'm the author) one would have to pay the price to coerce to a matrix
before using matrixStats::rowMaxs(). However, if it is that the
original data could equally well live in a matrix, then matrixStats
should be computational efficient for this task. (I've seen cases
where an original matrix was turned into a data.frame