Re: [R] Subset columns by prefix

2010-06-09 Thread Henrique Dallazuanna
Try this: subset(x, select = grep("cru", names(x))) On Wed, Jun 9, 2010 at 2:41 PM, Josh B wrote: > Hello R listserve, > > I would appreciate someone's help with this problem. Consider the following > toy dataset: > > x <- read.table(textConnection("worldclim.1 worldclim.2 cru.1 cru.2 > indv.1

[R] Subset columns by prefix

2010-06-09 Thread Josh B
Hello R listserve, I would appreciate someone's help with this problem. Consider the following toy dataset: x <- read.table(textConnection("worldclim.1 worldclim.2 cru.1 cru.2 indv.1 7 8 32 658 indv.2 7 7 39 422"), header = TRUE) How could I create a subset of the data based on the column prefi