if statement - Shifting Column Selection in Dataframe in R -


i have data frame 30 columns. goal select 5 columns @ time. based on condition, want shift selection in data frame 5 columns.

for example:

original dataframe column selection:

col6 col7 col8 col9 col10 

if condition true, select:

col1 col2 col3 col4 col5 

if condition false, select:

col11 col12 col13 col14 col15. 

i don't want call out specific columns though, want write general formula call out shift of 5 columns right or left based on whether condition true or false.

any great. thanks!

from asked developed following code. please clarify question if not looking for. assuming data frame df:

n <- 1  df[,n:n+4]  if (condition){   n <- n + 5 } else if (condition && n != 1) {   n <- n - 5 }  

Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -