Thanks to all the good suggestions/solutions to the original problem.
On 6/21/2017 3:28 PM, David Winsemius wrote:
>> On Jun 21, 2017, at 9:11 AM, Evan Cooch wrote:
>>
>> Suppose I have the following sort of dataframe, where each column name has a
>> common structure: prefix, followed by a numbe
> On Jun 21, 2017, at 9:11 AM, Evan Cooch wrote:
>
> Suppose I have the following sort of dataframe, where each column name has a
> common structure: prefix, followed by a number (for this example, col1, col2,
> col3 and col4):
>
> d = data.frame( col1=runif(10), col2=runif(10), col3=runif(10
Assume there 100 columns, named col1, col2,..., col100 in data frame d
+ maybe some more columns with various names preceding them. You want
col21 to col72.
nm <- names(d)
d[, which(nm == "col21"): which(nm == "col72") ]
## NB : if all you have is col1 to col100 the d[, 23:72] works fine.
See an
d[ , paste( "col", 2:4 ) ]
or
d[ , sprintf( "col%d", 2:4 ) ]
or
d[ , grep( "^col[234]$", names( d ) ]
Each approach has different ways of being flexible.
--
Sent from my phone. Please excuse my brevity.
On June 21, 2017 9:11:10 AM PDT, Evan Cooch wrote:
>Suppose I have the following sort of
Suppose I have the following sort of dataframe, where each column name
has a common structure: prefix, followed by a number (for this example,
col1, col2, col3 and col4):
d = data.frame( col1=runif(10), col2=runif(10),
col3=runif(10),col4=runif(10))
What I haven't been able to suss out is h
5 matches
Mail list logo