Re: [R] How to sum values across multiple variables using a wildcard?

2006-02-20 Thread mtb954
Thanks Gabor, Simon and Marc...I got this to work with the grep() and rowSums examples you provided. Mark On 2/20/06, Marc Schwartz <[EMAIL PROTECTED]> wrote: > On Mon, 2006-02-20 at 18:41 -0600, [EMAIL PROTECTED] wrote: > > I have a dataframe called "data" with 5 records (in rows) each of > >

Re: [R] How to sum values across multiple variables using a wildcard?

2006-02-20 Thread Marc Schwartz
On Mon, 2006-02-20 at 18:41 -0600, [EMAIL PROTECTED] wrote: > I have a dataframe called "data" with 5 records (in rows) each of > which has been scored on each of many variables (in columns). > > Five of the variables are named var1, var2, var3, var4, var5 using > headers. The other variables are

Re: [R] How to sum values across multiple variables using a wildcard?

2006-02-20 Thread Simon Blomberg
data <- data.frame(var1=c(1,2,3), var2=c(3,4,5), var3=c(4,5,6), foo = c(100,200,300)) # sum rows with "var" in their name rowSums(data[, grep("var", names(data))]) 1 2 3 8 11 14 [EMAIL PROTECTED] wrote: > I have a dataframe called "data" with 5 records (in rows) each of > which has been sc

Re: [R] How to sum values across multiple variables using a wildcard?

2006-02-20 Thread Gabor Grothendieck
See: ?rowSums On 2/20/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > I have a dataframe called "data" with 5 records (in rows) each of > which has been scored on each of many variables (in columns). > > Five of the variables are named var1, var2, var3, var4, var5 using > headers. The other

[R] How to sum values across multiple variables using a wildcard?

2006-02-20 Thread mtb954
I have a dataframe called "data" with 5 records (in rows) each of which has been scored on each of many variables (in columns). Five of the variables are named var1, var2, var3, var4, var5 using headers. The other variables are named using other conventions. I can create a new variable called var