Skip to content

Instantly share code, notes, and snippets.

@erzk
erzk / rename_and_join_raw_files.bat
Last active August 29, 2015 14:13
Prepare raw .res files
rename *.res *.csv
copy *.csv all_results_native_chinese.csv
@erzk
erzk / addPercentagesLMTool
Created January 12, 2015 13:04
adds percentages to new columns of the raw data file exported from LM Tool
Sub addPercentagesLMTool()
ActiveCell.FormulaR1C1 = "percPreApproved"
Range("I1").Select
ActiveCell.FormulaR1C1 = "percApproved"
Range("J1").Select
ActiveCell.FormulaR1C1 = "percPreRejected"
Range("K1").Select
ActiveCell.FormulaR1C1 = "percRejected"
Range("L1").Select
@erzk
erzk / DATEPARSE_from_DataSift
Created January 14, 2015 10:30
Tableau - Calculated field - Date parse data from DataSift
DATEPARSE("EEE, dd MMM yyy HH:mm:ss" ,[Interaction.Created At])
@erzk
erzk / copy_all.bat
Last active August 29, 2015 14:13
copy all files of a certain type from subfolders to another folder
for /R H:\... %%f in (*.csv) do copy %%f H:\...
@erzk
erzk / append_at_the_beginning.bat
Created January 25, 2015 21:52
Adds 'text' at the beginning of file names
REM adds 'abc' at the beginning of each txt file
FOR %v IN (*.txt) DO REN %v abc%v
@erzk
erzk / copy_all_no_subfolder_structure.bat
Last active August 29, 2015 14:14
Copy all files of a certain type from the source path (including subfolders) to the destination path (no subfolder structure)
REM copy all pdfs from the source path (including subfolders) to the destination path (no subfolder structure)
xcopy <source path>\*.pdf <destination path> /s
@erzk
erzk / wide_to_long.R
Created May 11, 2015 22:19
change format from wide to long
library(tidyr)
foreign_victims_wide <- read.csv("foreign_victims_wide.csv")
# reshape to long format
foreign_victims_long <- gather(foreign_victims_wide, Year, Victims, X1998:X2012)
# remove Xs
# could be omitted if using check.names=FALSE in read.csv()
foreign_victims_long$Year <- gsub("X", "", paste(foreign_victims_long$Year))
write.csv(foreign_victims_long, file = "foreign_victims_long.csv", row.names=FALSE)
library(ggplot2)
library(RColorBrewer)
# make the heatmap
# based on https://gist.github.com/dsparks/3710171
myPalette <- colorRampPalette(rev(brewer.pal(11, "Spectral")), space="Lab")
zp1 <- ggplot(foreign_victims_long,
aes(x = Year, y = Country, fill = Victims))
zp1 <- zp1 + geom_tile()
zp1 <- zp1 + scale_fill_gradientn(colours = myPalette(100))
@erzk
erzk / annotate_split.bat
Last active August 29, 2015 14:22
Annotates and splits a continuous wav file using Speech Filing System
REM define the working directory
set location=%cd%
REM define the participant
set participant=NAME
REM define the trial
set trial=01
REM define the condition
set condition=FAF-Up
REM define the file name, e.g. 01-NAME-FAF-Up.wav
set filename=%trial%-%participant%-%condition%
@erzk
erzk / get_mean_pitch.R
Created May 31, 2015 18:52
extracts duration and mean pitch
# Get mean pitch and duration
# Frequency altered feedback study
# PraatR documentation: http://www.aaronalbin.com/praatr/tutorial.html
# loop through all the files in a directory
library("PraatR")
library("phonTools")
# define the partcipant/folder/output file name
participant <- "NAME"