[R] loop through columns in a data frame

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Mon Mar 25 19:15:28 CET 2019


"Does anyone know how to use loop (or other methods) to create new columns?
In SAS, I can use array to get it done. But I don't know how to do it in R."

Yup. Practically all users of R know how, as this is entirely elementary.
You will too if you make the effort to go through a basic R tutorial, of
which there are many on the web (and one shipped with R).

Cheers,
Bert

On Mon, Mar 25, 2019 at 10:08 AM Yuan, Keming (CDC/DDNID/NCIPC/DVP) via
R-help <r-help using r-project.org> wrote:

> Hi All,
>
> I have a data frame with variable names like A_le, A_me, B_le, B_me, C_le,
> C_me....
> if A_le=1 or A_me=1 then  I need to create a new column A_new=1. Same
> operation to create columns B_new, C_new...
> Does anyone know how to use loop (or other methods) to create new columns?
> In SAS, I can use array to get it done. But I don't know how to do it in R.
>
> Thanks,
>
> Keming Yuan
> CDC
>
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list