Displaying 20 results from an estimated 5000 matches similar to: "Understanding tryCatch"
2011 Mar 10
1
tryCatch - Continuing for/next loop after error
Dear all,
I am not sure I understand fully the functionality of "tryCatch" and
"try" commands and how these are used to continue a for/next loop if an
error occurs within the loop.
Can somebody point me to material (or share some code) with more
extensive examples than the ones in the help/FAQ pages?
Do explain my problem in more detail:
for (i in 100:1000)
{
## do
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
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))
2010 Dec 07
3
More elegant magnitude method
I have a need to find the order of number to get a scaling parameter as a
power of 10. I have a function that works *so far*, but it is ugly and
probably buggy. In the interest of avoiding code-based outliers in my
data, I thought I would ask if anyone here has a better way.
> scl <- function(x){
+ length(charToRaw(format(trunc(x), scientific = F)))-1}
> a <- 123456789
> b <-
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
2004 Jun 15
3
Queue then Voicemail
Hi all,
I'm stuggling with how to present calleds to a specific DDI (DID) with Music on hold whilst the call is hunted around 3 phones, then if not answered within a certain period forwarded to voicemail.
So far I've got the queue working and the voicemail but not both together.
Ive had a look on the wiki and the archives but can't spot anything that might point me in the right
2010 Nov 01
1
Possible memory leak in loop.
I was trying to use memory.size() to determine whether a code loop I am
executing created a memory leak, since one replicate of the simulation
takes 670.98 seconds according to proc.time(), while 5 replicates takes
170762 seconds. So I set it up as:
memA <- memory.size()
looping code...
memB <- memory.size()
memA returns as 9.3, and memB returns 11.3. I'm not familiar with
2011 Mar 15
1
(no subject)
I was wondering if there is a way to get read in a single keystroke at a
time in R as a string, akin to ncurses-style interfaces. I looked into
readLines, readChar, etc. using stdin, but these all require the use of an
end of line. Has anyone ever had need to do this or have any ideas on how
to do this?
Thanks,
Jon
PS I apologize if this double-sends, but I am having mail client issues.
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