Re: [R] Loop through factors without changing to numerics

From: Francisco J. Zagmutt <gerifalte28_at_hotmail.com>
Date: Fri 20 Jan 2006 - 12:18:53 EST


An example would have helped to give you a better answer. You can use characters in the "seq" argument of the for loop. i.e

x=letters[1:4]
x
[1] "a" "b" "c" "d"

for(i in x) {print(i)}

[1] "a"
[1] "b"
[1] "c"
[1] "d"


Is this what you were looking for?

Francisco

>From: "Chia, Yen Lin" <yen.lin.chia@intel.com>
>To: <r-help@stat.math.ethz.ch>
>Subject: [R] Loop through factors without changing to numerics
>Date: Thu, 19 Jan 2006 16:42:00 -0800
>
>Hi all,
>
>
>
>If I want to write a for loop to loop through a set of factors, which
>are not coded in 1,2,3, for e.g in character, possible to write the for
>loop without changing it to categorical variables? I saw the manual
>mentions for loop will take a list, but I'm not sure how to create a
>list here. Any input will be appreciated. Thanks.
>
>
>
>Yen Lin
>
>
> [[alternative HTML version deleted]]
>
>______________________________________________
>R-help@stat.math.ethz.ch mailing list
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide!
>http://www.R-project.org/posting-guide.html



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Fri Jan 20 12:31:18 2006

This archive was generated by hypermail 2.1.8 : Fri 20 Jan 2006 - 14:09:27 EST