Displaying 20 results from an estimated 3000 matches similar to: "extracting row means from a list"
2011 Feb 10
2
Calculating rowMeans from different columns in each row?
Hello!
I have a dataset like this:
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
2009 May 15
2
Help with loops
Hi
I am trying to create a loop which averages replicates in my data.
The original data has many rows. and consists of 40 column zz[,2:41] plus row headings in zz[,1]
I am trying to average each set 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(average_value[,1])) {
2009 May 15
1
Fw: Help with loops(corrected question)
--- On Fri, 15/5/09, Amit Patel <amitrhelp at yahoo.co.uk> wrote:
> From: Amit Patel <amitrhelp at yahoo.co.uk>
> Subject: Help with loops
> To: r-help at r-project.org
> Date: Friday, 15 May, 2009, 12:17 PM
> Hi
> I am trying to create a loop which averages replicates in
> my data.
> The original data has many rows. and consists of 40 column
> zz[,2:41]
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)
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
2024 Jun 08
1
Can't compute row means of two columns of a dataframe.
John,
Maybe you can clarify what you want the output to look like. It took me a
while to realize what you may want as it is NOT properly described as
wanting rowsums.
There is a standard function called rowMeans() that probably does what you
want if you want the mean of all rows as in:
> rowMeans(xxxz)
[1] 84.33333 87.00000 89.66667 92.33333 95.00000 97.66667 100.33333
103.66667
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>
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.
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",
2011 Sep 20
1
means across list of data frames
I have a list of data frames like the following:
set.seed(123)
a<- data.frame(x=runif(10), y = runif(10), sample = seq(1,10))
b<- data.frame(x=runif(10), y = runif(10), sample = seq(1,10))
L<- list(a,b)
All data frames in the list have the same dimensions. I need to calculate
the sample means for x and y. The real data are lists of several thousand
quite large dataframes, so I need
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
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 with ?na.rm = TRUE?), that
2008 Jun 12
3
Problem with rowMeans()
Hi all,
I have a matrix called 'data', which looks like:
> data[1:4,1:4]
Probe_ID Gene_Symbol M1601 M1602
1 A_23_P105862 13CDNA73 -1.6 0.16
2 A_23_P76435 15E1.2 0.18 0.59
3 A_24_P402115 15E1.2 1.63 -0.62
4 A_32_P227764 15E1.2 -0.76 -0.42
> dim(data)
[1]
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)
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
2011 Feb 27
2
replacing missing values with row average
Hello,
I have some dataset, which i read it from external file using the (data <-
read.csv("my file location")) and read as a dataframe
> is(data)
[1] "data.frame" "list" "oldClass" "vector"
but i have also converted this into a matrix and tried to apply my code but
didnt work.
Anyways, suppose i have the following data.
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
>
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
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