Cheatography
https://cheatography.com
A cheatsheet for TariSauce
This is a draft cheat sheet. It is a work in progress and is not finished yet.
Combine multiple .txt files
//create a list of all.txt files in directory
list.txt<-dir(pattern = "*.txt")
//create an empty list
ldf<-list()
//for each file, load in, rename columns and add to ldf
for (i in 1:length(listtxt)){
// read each text file in
ldf[[i]] <- (read.delim(listtxt[i]))
//rename column names so all are the same
colnames(ldf[[i]]) <- c("Selection","View", "Channel", "Begin_Time", "End_Time", "Low_Freq",
"High_Freq", "Begin_Date", "Begin_Clock", "End_Clock", "Delta_Time","Notes")
}
//bind all files into one table
df<-do.call("rbind", ldf)
|
|
Combine multiple .csv files
//find any file that starts with file_ and extension .csv in current directory and store name of each file in a vector files
files<- list.files(pattern = "file_.*csv")
//read each file in files into a dataframe with read_csv() storing frames in df_list
df_list<-lapply(files, read_csv)
//concatenate all dataframes together
combine<-bind_rows(df_list)
|
|
Set up and Loading Data
set working directory |
setwd("file directory path") |
load packages |
library(package.name) |
import .csv file |
data<-read.csv("filename.csv", fileEncoding="UTF-8-BOM") |
import excel file |
data<-read.xlsx(choose.files("file.path", sheetName="file.name") |
Viewing and Basic Functions
view first 5 rows |
head(data) |
view last 5 rows |
tail(data) |
show dataframe structure |
str(data) |
mean(data$column) |
print mean of column |
median(data$column) |
print median of column |
var(data$column) |
print variance of column |
sd(data$column |
print standard deviation of column |
|
|
|