Re: [R] Repeating the same calculation across multiple pairs of variables

2011-03-04 Thread Dennis Murphy
Hi: Perhaps you had something like this in mind: df<-data.frame(a1=1:10, a2=11:20, a3=21:30, b1=101:110, b2=111:120, b3=121:130) avars <- names(df)[grep('^a', names(df))] bvars <- names(df)[grep('^b', names(df))] cvars <- paste('c', 1:length(avars), sep = '') df <- within(df, for(i in seq_along(c

Re: [R] Repeating the same calculation across multiple pairs of variables

2011-03-04 Thread Joshua Wiley
Hi Al, Assuming that the order of the matrices resulting from selecting "avars" and "bvars" is identical (it is at least in the example you gave), then you can do: dat <- data.frame(a1=1:10, a2=11:20, a3=21:30, b1=101:110, b2=111:120, b3=121:130) avars <- paste("a", 1:3, sep = '') bvars <- paste

[R] Repeating the same calculation across multiple pairs of variables

2011-03-04 Thread Al Roark
Hi all, I frequently encounter datasets that require me to repeat the same calculation across many variables. For example, given a dataset with total employment variables and manufacturing employment variables for the years 1990-2010, I might have to calculate manufacturing's share of total e