nievergeltlab
8/11/2017 - 8:09 PM

Rbind many files. note 1: List of files scanned in using the scan function, could easily be a .csv file instead. note 2: As well, the .cs

Rbind many files.

note 1: List of files scanned in using the scan function, could easily be a .csv file instead.

note 2: As well, the .csv file could include a list of names for the files to be used in the R environment (as opposed to what is used now, which is just the .csv file name. e.g. BAI_v2.csv could be simply BAI)

setwd('C:\\Users\\adam\\Desktop\\cross_phenotype_correlations\\MRS1')
library(plyr)

#Put data sheet names here, without .csv in the name
datasheets <- scan(what='character')
grievance_FINAL_VERSION2
AUDIT_FINAL_CH_mod
BAI_v2
BDI2_FINAL_v3
CAPS_FINAL
MINI_FINAL_2



#Read each file into a data frame with the same name as the .csv file
for (i in datasheets)
{
	assign(
		i, read.csv(paste(i,'.csv',sep=''), header=T, na.strings=c('999','NA'),stringsAsFactors=F)
		) 
}

#Parse the text list of data frame names as a list of data frames
data_list <- eval( 
			parse( 
				text=paste(
					"list(", paste(datasheets, collapse=','), ")" 
					)
				)
			)

            
#Combine all data frames
dat <- rbind.fill(data_list)

write.csv(dat,'data-name-here.csv',row.names=F)