similar to: Calculating a Maximum for a row or column with NA's

Displaying 20 results from an estimated 10000 matches similar to: "Calculating a Maximum for a row or column with NA's"

2005 Jun 13
3
To many NA's from mean(..., na.rm=T) when a column is all NA's
Dear R-help folks, I am seeing unexpected behaviour from the function mean with option na.rm =TRUE (which is removing a whole column of a data frame or matrix. example: testcase <- data.frame( x = 1:3, y = rep(NA,3)) mean(testcase[,1], na.rm=TRUE) [1] 2 mean(testcase[,2], na.rm = TRUE) [1] NaN OK, so far that seems sensible. Now I'd like to compute both means at once:
2010 Jun 10
2
counting Na/not NA by groups by column
# create a matrix with some random NAs in it > m<-matrix(NA,nrow=15,ncol=14) > m[,3:14]<-52 > m[13,9]<-NA > m[4:7,8]<-NA > m[1:2,5]<-NA > m[,2]<-rep(1800:1804, by=3) > y<-order(m[,2]) > m<-m[y,] > m[,1]<-rep(1:3,by=5) > m [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13] [,14] [1,] 1 1800 52 52 NA 52 52
2011 Sep 12
5
Hourly data with zoo
I have date data as a numeric and hourly data in 0 to 2300 hours in a dataframe. d <- rep(20110101,24) h <- seq(from = 0, to = 2300, by = 100) df <- data.frame(LST_DATE = d, LST_TIME = h, data = rnorm(24, 0, 1)) S <- chron(dates. = as.character(df$LST_DATE), times. = paste(as.character(df$LST_TIME/100), ":0:0", sep = ""), format =
2010 Apr 25
3
Noobie question on aggregate tapply and by
I have a 43MB dataframe ( 5 variables) and I'm trying to summarize subsets of the data. I've RTFM ( not very clear) and looked at a variety of samples but cant seem to figure out how to make these functions work. A sample of what I want to do would be this: ids<-seq(1,50) years<-c(rep(5,10),rep(6,10),rep(7,10),rep(8,20))
2003 Jun 08
6
Basic question on applying a function to each row of a dataframe
Hi, I have a function foo(x,y) and a dataframe, DF, comprised of two vectors, x & w, as follows : x w 1 1 1 2 2 1 3 3 1 4 4 1 etc I would like to apply the function foo to each 'pair' within DF e.g foo(1,1), foo(2,1), foo(3,1) etc I have tried >apply(DF,foo) >apply(DF[,],foo) >apply(DF[DF$x,DF$w],foo) However, none of the above worked. Can anyone help ?
2010 Jul 15
3
Summing over intervals
Given a matrix of MxN want to take the means of rows in the following fashion m<-matrix(seq(1,80),ncol=20, nrow=4) result<-matrix(NA,nrow=4,ncol=20/5) result[,1]<-apply(m[,1:5],1,mean) result[,2]<-apply(m[,6:10],1,mean) result[,3]<-apply(m[,11:15],1,mean) result[,4]<-apply(m[,16:20],1,mean) result [,1] [,2] [,3] [,4] [1,] 9 29 49 69 [2,] 10 30 50 70
2011 May 27
2
help with barplot
Hi, I'm really struggling with barplot I have a data.frame with 3 columns. The first column represents an "incident" type The second column represents a "month" The third column represents a "time" Code for a sample data.frame incidents <- rep(c('a','b','d','e'), each =25) months <- rep(c(1,2), each =10) times
2011 Jul 27
2
Elegant way to subtract matrix from array
there are really two related problems here I have a 2D matrix A <- matrix(1:100,nrow=20,ncol =5) S <- matrix(1:10,nrow=2,ncol =5) #I want to subtract S from A. so that S would be subtracted from the first 2 rows of #A, then the next two rows and so on. #I have a the same problem with a 3D array # where I want to subtract Q for every layer (1-10) in Z # I thought I solved this one
2009 Aug 11
1
Prevent sequential repeated values in data frame column
Hi, I'm trying to randomize a sequence of trials for an experimental design. The trials consist of values for each of two factors. As is there are 30 combinations of the two factors, and I want them to be ordered randomly but with the requirement that for one of the factors, the value can never be the same as the previous value. I'm currently randomizing my dataframe by using:
2010 Aug 11
2
Sweeping a zoo series
Given a long zoo matrix, the goal is to "sweep" out a statistic from the entire length of the sequences. longzoomatrix<-zoo(matrix(rnorm(720),ncol=6),as.yearmon(outer(1900,seq(0,length=120)/12,"+"))) cnames<-c(12345,23456,34567,45678,56789,67890) colnames(longzoomatrix)<-cnames longzoomatrix[1:24,] 12345 23456 34567 45678
2010 Jun 05
5
Matrix to Vector
Given a matrix of m*n, I want to reorder it as a vector, using a row major transpose. so: > m<-matrix(seq(1,48),nrow=6,byrow=T) > m [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [1,] 1 2 3 4 5 6 7 8 [2,] 9 10 11 12 13 14 15 16 [3,] 17 18 19 20 21 22 23 24 [4,] 25 26 27 28 29 30 31 32 [5,] 33 34 35 36 37
2011 Mar 18
2
Understanding tryCatch
I've read the help and the archives on tryCatch but I'm still stuggling trying to understand how it works exactly and how I can use it to get the result I need. I have a data.frame of urls which point to 11 .zip files. Basically I use RCurl to get the list of files from a ftp and then reduce that directory dump to the 11 zip files I want to download. Its easy enough to do that in a loop
2010 May 18
2
get the row sums
> head(en.id.pr) valid.gene_id b.pred rf.pred svm.pred 1521 2500151211 0 0 0 366 639679745 0 0 0 1965 2502081603 1 1 1 1420 644148030 1 1 1 1565 2500626489 1 1 1 1816 2501711016 1 1 1 > p.pred <- data.frame(en.id.pr, sum=apply(en.id.pr[,2:4], 1, sum)) #
2008 Jul 23
3
sum each row and output results
Hello, I have the following data frame (DF): V5 V5.1 V5.2 V5.3 V5.4 V5.5 2 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 3 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 4 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677 -6498.7183 5 -5890.18905 -6019.84665 -6211.06545 -6198.9353 -6616.8677
2008 Oct 22
3
retrieving matrix elements by giving pairs of row AND column numbers?
Hi, this is probably a very trivial question but I can't figure out the right terms to find the solution in the list archive. I have a matrix or a data.frame or the like: > m <- matrix(ncol=3,seq(1,9)) > m [,1] [,2] [,3] [1,] 1 4 7 [2,] 2 5 8 [3,] 3 6 9 and now I wonder if one can provide somehow two vectors, one containing row numbers, the other
2010 May 03
2
Adding a header after the file is written
The situation arises where I open a file to write a data.frame to it. with write.table. multiple lines are written to the file and the file is kept in Append=TRUE mode. If one sets the col.names to the names of the variables being written, you have output that looks like this... name1 name2 name3..... x x x x x x x x x name1 name2 name
2011 Mar 11
2
insertion of a row between individuals
Can someone help with a fairly simple task? I have a data set where I would like to insert a 0 time event between individuals: what I have: VAR DATE TIME CONC COVAR 1 NOV2 0.25 10 group1 1 NOV2 0.5 20 group1 1 NOV2 1 5 group1 1 NOV2 2 1 group1 1 NOV2 3 0.1 group1 2 NOV2 0.25 10
2008 Dec 28
0
how to calculate DWT maximum decomposition level
Given a time series of length N, I am trying to figure out its maximum DWT decomposition level. With reference to "dwt" function of R package "wavelets", running the provided example I get the following and wonder how the maximum decomposition level (which is not an integer number) is calculated. I tried myself the formula in the on-line documentation but could not get the
2012 Jul 17
3
Finding the column with the maximum value by row
Hi, Let's say I have the following data: > a=matrix(c(1,2,4,4,2,1,1,2,4),nrow=3,byrow=T) > a [,1] [,2] [,3] [1,] 1 2 4 [2,] 4 2 1 [3,] 1 2 4 What syntax should I use to get R to tell me the column that corresponds to the maximum value for each row? For my example, I would like to get a vector that says 3, 1, 3 because the maximum value for row 1 is
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