similar to: Noobie question on aggregate tapply and by

Displaying 20 results from an estimated 700 matches similar to: "Noobie question on aggregate tapply and by"

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 =
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
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
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 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
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 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
2010 Aug 09
1
nested 'by'
Assuming a data frame or matrix with two columns representing variable that you want to aggregate over. you want to calculate column means, by year, for each Id example<-data.frame(id=c(rep(12345,5),rep(54321,6),rep(45678,7)),Year=rep(seq(1900,1902,by=1),6), x=seq(1,18,by=1),y=seq(18,1,by=-1)) example id Year x y 1 12345 1900 1 18 2 12345 1901 2 17 3 12345 1902 3 16 4 12345
2011 Nov 01
1
weird error
I was just rebuilding a package that has built before and I hit this error Error in loadNamespace(package, c(which.lib.loc, lib.loc), keep.source = keep.source) : cyclic name space dependency detected when loading 'GhcnDaily', already loading 'GhcnDaily' The package built just fine last revision, and the only changes I made were to Rd files How do I track this puppy down
2010 May 04
1
error in La.svd Lapack routine 'dgesdd'
Error in La.svd(x, nu, nv) : error code 1 from Lapack routine ‘dgesdd’ what resources are there to track down errors like this [[alternative HTML version deleted]]
2010 Jun 14
1
recursively Merging a list a zoo objects
The zoo package as a merge function which merges a set of zoo objects result<-merge(zoo1,zoo2,...) Assume your zoo objects are already collected in a list # make a phony list to illustrate the situation. ( hat tip to david W for constructing a list in a loop) ddat <- as.list(rep("", 20)) ytd<-seq(3,14) for(i in 1:20) { + ddat[[i]] <- zoo(data,ytd ) + } ddat [[1]] 1 2
2010 Aug 15
1
Trouble loading "saved" Rdata
In the particular application I have I save "test.Rdata" to a sub directory dir<-"Example" dir.create(dir) test<-data.frame(a=c(1,2,3),b=c(3,4,5) full<-file.path(dir,"test.Rdata,fsep=.Platform$file.sep) save(test,file=full) load(full) returns NULL it works fine when the object is saved to the working directory, but fails when saved to a sub directory. The Rdata
2010 Aug 20
1
differecing a zoo series
A quick question x <- as.yearmon(2000 + seq(0, 23)/12) x [1] "Jan 2000" "Feb 2000" "Mar 2000" "Apr 2000" "May 2000" "Jun 2000" "Jul 2000" "Aug 2000" "Sep 2000" "Oct 2000" "Nov 2000" "Dec 2000" "Jan 2001" [14] "Feb 2001" "Mar 2001" "Apr
2010 Sep 21
1
diagnosing download.file() problems
I'm accessing around 95 tar files on an FTP server ranging in size between 10 and 40MB a piece. while certainly can click on them and download them outside of R, I'd like to have my script do it. Retrieving the ftp directory with RCurl works fine (about 90% of the time) but downloading the files by looping through all the files is a random process. I may get 1-8 files download and then
2010 Dec 21
1
lm() on a matrix of zoo series
I have a matrix of zoo series. each series is in a column. x <- as.yearmon(2000 + seq(0, 23)/12) # 24 months of data, lets make 20 sets of random data testData <- matrix(rnorm(480),ncol=20) # make a zoo object and columns will hold the 20 series TestZoo <- zoo(testData,order.by=x) # now run lm for just one series. m <- lm(TestZoo[,1]~time(TestZoo))$coeff[2] m time(TestZoo)
2010 May 05
1
extracting a matched string using regexpr
Given a text like I want to be able to extract a matched regular expression from a piece of text. this apparently works, but is pretty ugly # some html test<-"</tr><tr><th>88958</th><th>Abcdsef</th><th>67.8S</th><th>68.9\nW</th><th>26m</th>" # a pattern to extract 5 digits > pattern<-"[0-9]{5}" #
2010 Oct 09
1
Loss of precision in read.csv.
Given a csv file from this location Airports<-"http://www.ourairports.com/data/airports.csv" download.file(Airports,basename(Airports)) airports <-read.csv("airports.csv",encoding="UTF-8") > airports[1,] id ident type name latitude_deg longitude_deg elevation_ft continent iso_country iso_region municipality scheduled_service 1 6523
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
2010 Sep 05
2
merging two maxtrices
j<-matrix(nrow=10,ncol=10) k<-matrix(seq(1:50), ncol=10) row.names(k) <- seq(2,10,by=2) j [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] NA NA NA NA NA NA NA NA NA NA [2,] NA NA NA NA NA NA NA NA NA NA [3,] NA NA NA NA NA NA NA NA NA NA [4,] NA NA NA NA NA NA NA NA NA NA [5,] NA