Re: [R] loop through columns in a data frame

2019-03-26 Thread Yuan, Keming (CDC/DDNID/NCIPC/DVP) via R-help
through columns in a data frame R Notebook You forgot to provide what your test data looks like. For example, are all the columns a single letter followed by “_" as the name, or are there longer names? Are there always matched pairs (‘le’ and ‘me’) or can singles occur? Hide library(tidy

Re: [R] loop through columns in a data frame

2019-03-25 Thread Bert Gunter
"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, o

Re: [R] loop through columns in a data frame

2019-03-25 Thread jim holtman
R Notebook You forgot to provide what your test data looks like. For example, are all the columns a single letter followed by “_" as the name, or are there longer names? Are there always matched pairs (‘le’ and ‘me’) or can singles occur? Hide library(tidyverse)# create some data test <- tibble(a

[R] loop through columns in a data frame

2019-03-25 Thread Yuan, Keming (CDC/DDNID/NCIPC/DVP) via R-help
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