R/reinsort.col.R

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# reinsort.col 
# Description: sortiert Spalte(n) (toreinsort) in Datensatz an bestimmte Stelle (after)
# Status: beta
# Release Date: 	2011-09-07
# Author:    Martin Hecht
# Change Log:
#			
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

reinsort.col <- function ( dat , toreinsort , after ) {

		stopifnot ( is.data.frame ( dat ) )
		if ( is.character ( toreinsort ) ) toreinsort <- which ( colnames ( dat ) %in% toreinsort )
		if ( is.character ( after ) ) after <- which ( colnames ( dat ) %in% after )
		stopifnot ( is.numeric ( toreinsort ) )
		stopifnot ( is.numeric ( after ) )
		stopifnot ( ! identical ( toreinsort , integer(0) ) )
		stopifnot ( ! identical ( after , integer(0) ) ) 
		
		sorted <- c ( which ( ! (1:after) %in% toreinsort ) , toreinsort , which ( ! seq ( along = colnames ( dat ) ) %in% c ( 1:after , toreinsort ) ) ) 

		dat <- dat [ , sorted ]
		
}		

Try the eatTools package in your browser

Any scripts or data that you put into this service are public.

eatTools documentation built on May 2, 2019, 4:44 p.m.