Displaying 20 results from an estimated 239 matches for "rowmeans".
2009 May 15
2
Help with loops
...i.e. zz[1,2:3] averaged and placed in average_value[1,2] and so on.
below is my script but it seems to be stuck in an endless loop
Any suggestions??
for (i in 1:length(average_value[,1])) {
average_value[i] <- i^100; print(average_value[i])
#calculates Meanss
#Sample A
average_value[i,2] <- rowMeans(zz[i,2:3])
average_value[i,3] <- rowMeans(zz[i,4:5])
average_value[i,4] <- rowMeans(zz[i,6:7])
average_value[i,5] <- rowMeans(zz[i,8:9])
average_value[i,6] <- rowMeans(zz[i,10:11])
#Sample B
average_value[i,7] <- rowMeans(zz[i,12:13])
average_value[i,8] <- rowMeans(zz[i,14:15])
a...
2009 May 15
1
Fw: Help with loops(corrected question)
...et of values (i.e. zz[1,2:3]
> averaged and placed in average_value[1,2] and so on.
> below is my script but it seems to be stuck in an endless
> loop
> Any suggestions??
>
> for (i in 1:length(zz[,1])) {
>
> #calculates Meanss
> #Sample A
> average_value[i,2] <- rowMeans(zz[i,2:3])
> average_value[i,3] <- rowMeans(zz[i,4:5])
> average_value[i,4] <- rowMeans(zz[i,6:7])
> average_value[i,5] <- rowMeans(zz[i,8:9])
> average_value[i,6] <- rowMeans(zz[i,10:11])
>
> #Sample B
> average_value[i,7] <- rowMeans(zz[i,12:13])
> average_...
2013 May 11
1
How to repeat 2 functions in succession for 400 times? (microarray data)
Hi,
May be this helps:
?set.seed(24)
?mydata4<- as.data.frame(matrix(sample(1:100,10*38,replace=TRUE),ncol=38))
?dim(mydata4)
#[1] 10 38
?library(matrixStats)
res<-do.call(cbind,lapply(1:400, function(i) {permutation<-sample(mydata4); (rowMeans(permutation[,1:27])-rowMeans(permutation[,28:38]))/(rowSds(permutation[,1:27])+rowSds(permutation[,28:38]))} ))
?dim(res)
#[1]? 10 400
A.K.
>I want to do permutation test and then get a PGC score 400 times on mydata4 (microarray data)
>
>I use 2 functions as below:
>1. permutation&...
2012 Oct 12
1
Error in rowMeans function
Hello,
I am trying to create parcels for a CFA model. I am trying to average 6 sets of 3 variables each into parcels. I don't understand why I am getting an error message as follows:
Thanks for your help,
Catherine
atds1par <- rowMeans(semHW1dat1[, c("atds1", "atds2", "atds3")], na.rm=TRUE)
atds2par <- rowMeans(semHW1dat1[, c("atds4", "atds5", "atds6")], na.rm=TRUE)
atds3par <- rowMeans(semHW1dat1[, c("atds7", "atds8", "atds9")], na....
2007 Nov 25
2
rowMean, specify subset of columns within Dataframe?
I would like to calculate the mean of tree leader increment growth over 5
years (I1 through I5) where each tree is a row and each row has 5 columns.
So far I have achieved this using rowMeans when all columns are numeric type
and used in the calculation:
Data1 <- data.frame(cbind(I1 = 3, I2 = c(0,3:1, 2:5,NA), I3
=c(1:4,NA,5:2),I4=2,I5=3))
Data1
Data1$mean_5 <- rowMeans(Data1, na.rm =T)
Data1
My real dataset has many columns including several Factor type. Is it
possible to speci...
2011 Feb 10
2
Calculating rowMeans from different columns in each row?
...his:
X1 X2 X3 X4 X5 X6 X7 X8
1 2 2 1 2 3 2 6
2 3 2 5 7 9 1 3
1 9 12 6 1 1 3 6
The columns X1-X6 contains ordinary numeric values.
X7 contains the number of the first column that the rowMeans should be calculated from and
X8 contains the last column that should be included in the rowMeans.
when I try
test <- (df[,df$X7:df$X8])
the rowMeans are calculated based on the values in the X7 and X8 in the first row only.
Thanks in advance!
/Marine
2008 Jun 12
3
Problem with rowMeans()
...5
What I want to do is to make a new matrix called 'data2', which would be
transformed
by subtracting the mean of each row from matrix 'data'. There are some 'NA's
in the
matrix and I do want to keep it.
I tried to take 'mean's from each row first by using:
a<- rowMeans(data[,3:85],na.rm = FALSE)
but I got:
> a<- rowMeans(data[,3:85],na.rm = FALSE)
Error in rowMeans(data[, 3:85], na.rm = FALSE) : 'x' must be numeric
Can anybody suggest me how to get around this?
Thank you very much!
Allen
[[alternative HTML version deleted]]
2011 Apr 05
1
Inconsistency between rowMeans documentation and reality?
Dear List,
I'm not even sure this is an issue or not, but ?rowMeans has:
Value:
A numeric or complex array of suitable size, or a vector if the
result is one-dimensional. The ?dimnames? (or ?names? for a
vector result) are taken from the original array.
If there are no values in a range to be summed over (after
removing missing values w...
2017 Apr 01
3
mean(x) != mean(rev(x)) different with x <- c(NA, NaN) for some builds
In R 3.3.3, I observe the following on Ubuntu 16.04 (when building
from source as well as for the sudo apt r-base build):
> x <- c(NA, NaN)
> mean(x)
[1] NA
> mean(rev(x))
[1] NaN
> rowMeans(matrix(x, nrow = 1, ncol = 2))
[1] NA
> rowMeans(matrix(rev(x), nrow = 1, ncol = 2))
[1] NaN
> .rowMeans(x, m = 1, n = 2)
[1] NA
> .rowMeans(rev(x), m = 1, n = 2)
[1] NaN
> .rowSums(x, m = 1, n = 2)
[1] NA
> .rowSums(rev(x), m = 1, n = 2)
[1] NaN
> rowSums(matrix(x, nrow = 1, n...
2011 Feb 27
2
replacing missing values with row average
...<- as.data.frame(matrix(rnorm(100), nrow = 10))
And let's put some missing values
data[sample(1:10, 3), sample(1:10, 3)] <- NA
I want to replace all NA's by row averages or column averages of my matrix.
I tried to use(with my original data matrix)
data[is.na(data)] <- rowMeans(data, na.rm = TRUE)
But got an error message of
Error in rowMeans(data, na.rm = TRUE) : 'x' must be numeric
Then I converted data<- as.matrix(data)
data<- as.numeric(data)
And applying my code
data[is.na(data)] <- rowMeans(data, na.rm = TRUE)
Error...
2010 Jun 01
2
Problem using apply
Hello ,
I can not get apply function to do what I want when doing stuff on rows.
Let's say I want to divide the rows of matrix by their mean, the below show
you get the same result weather you use 1 or 2, i.e. same result for columns
than for means..:(
Thanks a lot for the help,
m = matrix( c(1,4,7,4,5,8,7,8,9), nrow = 3 )
divideByMean = function( v ){
return(
2004 Jul 01
3
list structure question
Hi,
I have a list in which element is a vector (all of the same length and
all numeric). I want to find the mean of the first elements of the
vectors, the mean of the second elements of the vectors and so on.
Currently I convert the list to a data.frame and apply rowMeans(). But
is there a way to to do this directly on the list? I seem to recall a
post in which there was such a function (or expression) but I just cant
seem to find it.
Could somebody point me in the right direction?
-------------------------------------------------------------------
Rajarshi Guha &...
2005 Jul 19
3
extracting row means from a list
...oo <- list()
for(i in 1:10){
# The real data are read in from a series of numbered text files
foo[[i]] <- data.frame(x1 = rnorm(100), x2 = rnorm(100), x3 =
rnorm(100),
x4 = rnorm(100), x5 = rnorm(100), x6 =
rnorm(100))
}
str(foo)
# by hand
mean.x1 <-
rowMeans(cbind(foo[[1]][,1],foo[[2]][,1],foo[[3]][,1],foo[[4]][,1],foo[[5]][
,1]),
foo[[6]][,1],foo[[7]][,1],foo[[8]][,1],foo[[9]][,1
],foo[[10]][,1]))
mean.x2 <-
rowMeans(cbind(foo[[1]][,2],foo[[2]][,2],foo[[3]][,2],foo[[4]][,2],foo[[5]][
,2]),
foo[[6]...
2008 Mar 05
1
Question on "assign(paste.."
...4,0.285);#for Trt 4
for (t in 4){
assign(paste("Trt",t,sep=""),rmultinom(10, size = 5,
prob=probTrt[t,]));
}
But the following does not work.
for (t in 4){
assign(paste("Trt",t,sep=""),rmultinom(10, size = 5,
prob=probTrt[t,]));
rowMeans(paste("Trt",t,sep=""));
}
How can I use it in functions like rowMeans so that I don't have to type all
the object names? Thank you.
Kyeongmi
[[alternative HTML version deleted]]
2006 Jul 06
2
tapply question
...ould be exactly the same except
that the AAA column would be
6 comes from (11 + 1)/2
7 comes from (12 + 2)/2
3 stays 3 because the element in the other AAA is zero
so i don't want to average that one. it shoulsd just stay 3.
So, I do
DF[DF == 0]<-NA
rowaverage<-function(x) x[rowMeans(forecastDf[x],na.rm=TRUE)
revisedDF<-tapply(seq(DF),names(DF),rowmeans)
there are two problems with this :
1) i need to go through the rows of the same name, not the columns
so i don't think seq(DF) is right because that goes through
the columns but i want to go through rows.
2) BBB will...
2008 Oct 31
4
[ifelse] how to maintain a value from original matrix without probs?
Dear all,
I have a matrix with positive and negative values.
>From this I would like to produce 2 matrices:
1st - retaining positives and putting NA in other positions
2nd - retaining negatives and putting NA in other positions
and then apply rowMeans for both.
I am trying to use the function ifelse in the exemplified form:
ifelse(A>0,A,NA)
but by putting A as a 2nd parameter it changes dimensions of the original
object.
I wonder if I can do this, as it seems not to difficult.
thanks in advance
[[alternative HTML version deleted]]
2005 Mar 10
1
contrast matrix for aov
...have 8 subjects in each cell (a balanced design) and we want to
specify the interaction contrast so that:
CueLeft>CueRght for the Right Hemisphere
CueRght>CueLeft for the Left Hemisphere.
Here is a copy of the relevant commands for R:
########################################
lh_cueL <- rowMeans( LHroi.cueL[,t1:t2] )
lh_cueR <- rowMeans( LHroi.cueR[,t1:t2] )
rh_cueL <- rowMeans( RHroi.cueL[,t1:t2] )
rh_cueR <- rowMeans( RHroi.cueR[,t1:t2] )
roiValues <- c( lh_cueL, lh_cueR, rh_cueL, rh_cueR )
cuelabels <- c("CueLeft", "CueRight")
hemlabels <- c("...
2017 Apr 01
1
mean(x) != mean(rev(x)) different with x <- c(NA, NaN) for some builds
...3.3.3, I observe the following on Ubuntu 16.04 (when building
>> from source as well as for the sudo apt r-base build):
>>
>>> x <- c(NA, NaN)
>>> mean(x)
>>
>> [1] NA
>>>
>>> mean(rev(x))
>>
>> [1] NaN
>>
>>> rowMeans(matrix(x, nrow = 1, ncol = 2))
>>
>> [1] NA
>>>
>>> rowMeans(matrix(rev(x), nrow = 1, ncol = 2))
>>
>> [1] NaN
>>
>>> .rowMeans(x, m = 1, n = 2)
>>
>> [1] NA
>>>
>>> .rowMeans(rev(x), m = 1, n = 2)
>>
>&...
2009 Jan 27
1
Problem with RMA using limma, oligo and pdInfoBuilder packages
...age")
[1] "oligoClasses"
> class(phenoData)
[1] "standardGeneric"
attr(,"package")
[1] "methods"
> eset <- rma(test)
Background correcting
Normalizing
> e <- exprs(eset)
> index1 <- 1:5
> index2 <- 6:10
> d <- rowMeans(e[, index1]) - rowMeans(e[, index2])
> design <- model.matrix(~factor(eset$Key))
> fit <- lmFit(eset, design)
> ebayes <- eBayes(fit)
> sample <- row.names(ebayes)
> Pvalue <- ebayes$p.value[,2]
> Mean1 <- rowMeans(e[,index1])
> Mean2 <- rowMeans(e...
2012 Jun 09
1
Inf and NA
Hi all,
I have a csv matrix "KT.csv" and it has Inf and NA
I want to calculate the mean of each row so I use
rowMeans(KT,na.rm = TRUE) but with this Inf cannot be omminted.
I?m trying to use before running rowMeans(KT,na.rm = TRUE)
KT<-range(KT,finite=TRUE)
but it doesn?t works...
Do you know a simple way to ommit Inf en the calculations?
Many thanks.
I have tried also to replace Inf by NA bt also I dind?...