[R] Creating loops with strings
Duncan Murdoch
murdoch at stats.uwo.ca
Wed Sep 23 01:58:05 CEST 2009
On 22/09/2009 4:50 PM, Rakknar wrote:
> Hello. I'm trying to run a series of commands in two different datasets. For
> make it efficient I want to make a loop for it. Until now the only command
> for loops i found it's the for() command it's only for series of numbers and
> not a series of strings,
What gave you that idea? A for loop can loop over any vector.
witch it's what i'm needing. It would be something
> like this
>
> for(i in dataset1 dataset2) {
Use
for (i in c("dataset1", "dataset2"))
to set i to each of those strings in turn.
> i <- read.dta("dataset1.dta")
> ls()
> summary(i)
> str(i)
> attach(i)
> }
None of the above will work, but it's almost all a bad idea anyway.
Duncan Murdoch
>
> I hope the idea it's clear. I'm using 2.9.1 Windows Version of R.
>
> Thanks.
More information about the R-help
mailing list