similar to: What am I doing wrong in my loops?

Displaying 20 results from an estimated 30000 matches similar to: "What am I doing wrong in my loops?"

2010 Apr 01
2
pdf files in loops
I need to make a bunch of PDF files of histograms. I tried gatelist = unique(mdf$ArrivalGate) for( gate in gatelist) { outfile = paste("../", airport, "/", airport, "taxiHistogram", gate, ".pdf", sep="") pdf(file = outfile, width = 10, height=8, par(lwd=1)) title=paste("Taxi time for Arrival Gate", gate, "by
2010 Apr 16
6
bwplot puts the bars in the wrong place
Dear R-Help, With the attached data set, I am still getting incorrect bwplots > xyplot(gdf$tt~gdf$OnHour |gdf$Runway, data=gdf) # Is correct > bwplot(gdf$tt~gdf$OnHour |gdf$Runway, data=gdf, horizontal=FALSE) # Puts the boxes on the wrong x-axis values # look especially at 0 and 3. How do I fix this? What is happening? Thanks, Jim Rome
2010 Jan 18
3
Using the output of strsplit
I successfully combined my data frames, and am now on my next hurdle. I had combined the data and quarter, and used tapply to count the entries for each unique date/quarter pair. ar= tapply(ewrgnd$gw, list(ewrgnd$dq), sum) #for each date/quarter combination sums the gw (which are all 1) dq=row.names(ar) spl=strsplit(dq) But I need to split them back into the separate date and quarter. So I used
2011 May 25
2
Importing fixed-width data
I have a data set where the lines look like: 2011-05-13 00:00:00 EONAAL330 dfa13002516PSCNONA 2011-05-13 00:00:01 EONAAL223 laa13044510AS.NONM Some lines are missing the field before and after the NON: 2011-05-13 00:00:05 EONBHS229 mia13001621NON I read them into R using df = read.fwf(file, widths=c(19,-4,7,3,8,2,1,3,1),
2011 Jun 08
3
How to suppress factor labels
I am using ggplot2 to make a boxplot that overlays a scatterplot: pp = qplot(time, error, data=times, size=I(1), geom="jitter", main=title, ylab="Error (min)", xlab="Time before ON (min)", alpha=I(1/10), color=times$runway, ylim=c(-30,40)) pp2 = pp + with(times, facet_wrap(~ runway, ncol=2)) print(pp2 + geom_boxplot(alpha=.5,
2010 Mar 20
3
How to select a row from one dataframe that is "close" to a row in another dataframe
I have two data frames of flight data, but they have very different numbers of rows. They come from different sources, so the data are not identical. > names(oooi) [1] "FltOrigDt" "MkdCrrCd" [3] "MkdFltNbr" "DprtTrpnStnCd" [5] "ArrTrpnStnCd" "ActualOutLocalTimestamp"
2010 Jan 16
3
Comparing dates in dataframes
I have two data frames. One (arr) has all arrivals to an airport for a year, and the other (gw) has the dates and quarter hour of the day when the weather is good. arr has a Date and quarter hour column. >names(arr) [1] "Date" "weekday" "hour" "month" "minute" [6] "quarter" "ICAO"
2011 Jun 09
2
Problem with a if statement inside a function
I have a really long functions, and at the end of the function, I am using a if statement to tag certain keywords based on whether they have certain values contained in them. However, the if statement doesn't seem to work. When I had split up the commands into various functions, it worked fine, but I'm not sure what going on now that it's combined into a single function. myfunc
2010 Feb 02
2
Writing out csv files
In my code, I calculate the maximum values with 2 factors using maxr=with(arrdf, tapply(rate,list(weekday,quarter), max, na.rm=T)) and I want to write out the file so that Excel can read it. I used write.table(maxr, fname, sep=",", col.names=TRUE, row.names=TRUE, quote=TRUE, na="0") which works, and yields something like
2011 Jun 10
1
Double x grid in ggplot2
I am trying to overlay raw data with a boxplot as follows: pp = qplot(factor(time, levels=0:60, ordered=TRUE), error, data=dfsub, size=I(1), main =" title", ylab="Error (min)", xlab="Time before ON (min)", alpha=I(1/10), ylim=c(-30,40), geom="jitter") + facet_wrap(~ runway, ncol=2) +
2011 Jul 17
1
How to speed up interpolation
df is a very large data frame with arrival estimates for many flights (DF$flightfact) at random times (df$PredTime). The error of the estimate is df$dt. My problem is that I want to know the prediction error at each minute before landing. This code works, but is very slow, and dominates everything. I tried using split(), but that rapidly ate up my 12 GB of memory. So, is there a better R way of
2011 Jun 07
2
ggplot2 and facet
I have a data frame (attached) that has interpolated EOT errors for each minute before flight landing. It also has the runway and an index for the flight: > > times[1:4,] time error runway flight 1 0 -0.02206235 04R 1 2 1 -0.07961631 04R 1 3 2 -0.13795380 04R 1 4 3 -0.20726073 04R 1 > > sapply(times, class) time error
2011 Aug 27
2
Am having trouble calling a function
In my main R program, I have source("retaanalysis/Functions/doAirport.R") .... stuff to read data and calculate ads sapply(ads, function(x) {doAirport(x, base)} ) And doAirport has # analyze the flights for a given airport doAirport = function(df, base) { # Get rid of unused runway factor levels (from other airports) df$lrw <- drop.levels(df$lrw) # In gdata package #
2004 Jan 15
3
Extracting multiple elements from a list
For a long time I've wanted a way to conveniently extract multiple elements from a list, which [[ doesn't allow. Can anyone suggest an efficient function to do this? Wouldn't it be a sensible addition to R? For example, alist <- list() alist[[1]] <- list() alist[[1]]$name <- "first" alist[[1]]$vec <- 1:4 alist[[2]] <- list() alist[[2]]$name <-
2003 Nov 13
1
Can't get Sweave syntax highlighting with Emacs
I can't get Emacs to automatically do syntax highlighting of Sweave files. I have followed Friedrich's suggestion for code to insert into my .emacs file. The complete section from my .emacs file is given below. When I load a *.Snw file, font is white until I press M-x, then the first code and document chunks get highlighted, but not the rest of the file. Latex and Noweb menus are
2007 Oct 16
2
How to speed up multiple for loop over list of data frames
Hi there, I have a multiple for loop over a list of data frames for ( i in 1:(N-1) ) { for ( j in (i+1):N ) { for ( p in 1:M ) { v_i[p] = alist[[p]][i,"v"] v_j[p] = alist[[p]][j,"v"] } rho_s = cor(v_i, v_j, method = "spearman") rho_p = cor(v_i, v_j, method = "pearson"
2012 Oct 04
2
How to build a list with missing values? What is missing, anyway?
This is tangentially related to Hadley's question. Suppose I'm building a function programmatically; I have assembled an expression for the body and I know the names of the arguments it wants to take. Suppose I have some convenience function such that writing make_function(alist(a=, b=), quote(a+b), environment()) is equivalent to writing function(a,b) a+b So how do I make the
2008 Oct 01
2
Bug or feature with finding a list element?
This seems odd. When I try to look up a list element which has a space in the name using just the first word (i.e. no spaces), it will sometimes return the element with a space in the name and sometimes it will return NULL. Try this: alist <- list( 'hello'=10, bye=20, 'hello world'=30, 'goodbye world'=40, 'hi world'=50, 'goodbye foo'=60, 'goodbye
2013 Mar 28
2
how to search a list that contains multiple dissimilar vectors?
Dear All, This is a simple question, but I'm stumped about the simplest way to search a list object such as the following: This randomish snippet: n <- c(round(runif(round(runif(1,1,10),0),1,10),0)) alist <- new("list") for (i in seq_along(n)) { alist[[i]] <- c(round(runif(round(runif(1,1,10),0),1,10),0)) } names(alist) <- sample(letters[1:length(n)]) rm(n);c(alist)
2006 Nov 06
5
alist()
In trying to get NULL members into a list, I found out about alist(). x<-alist() x$one<-1 x$two<-NULL but x$two doesn't exist. It seems, though, that an alist is just a list. How can one put NULL members into a list?