This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Read in all csv files in directory | |
files <- list.files(pattern = "*.csv") | |
# Create dfs for each csv then create list | |
for (i in 1:length(files)) | |
assign(files[i], | |
read.csv(files[i])) | |
lst <- mget(ls(pattern = "*.csv")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#From https://stackoverflow.com/questions/1401904/painless-way-to-install-a-new-version-of-r | |
# Run in the old version of R (or via RStudio) | |
setwd("C:/Temp/") | |
packages <- installed.packages()[,"Package"] | |
save(packages, file="Rpackages") | |
# INSTALL NEW R VERSION | |
if(!require(installr)) { install.packages("installr"); require(installr)} #load / install+load installr | |
# See here for more on installr: https://www.r-statistics.com/2013/03/updating-r-from-r-on-windows-using-the-installr-package/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
##arrange df vars by position | |
# from https://stackoverflow.com/questions/5620885/how-does-one-reorder-columns-in-a-data-frame | |
##'vars' must be a named vector, e.g. c("var.name"=1) | |
# e.g. | |
# table <- data.frame(Time=c(1,2), In=c(2,3), Out=c(3,4), Files=c(4,5)) | |
# arrange.vars(table, c("Out"=2)) | |
# arrange.vars(table, c("Out"=2, "Files"=1, "Time"=4)) | |
arrange.vars <- function(data, vars){ | |
##stop if not a data.frame (but should work for matrices as well) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Split column into multiple based on spaces, extra characters, etc. | |
df <- data.frame(x= c("crust (5)","things (3)","stuff (8)")) | |
library(tidyr) | |
df2 <- extract(df, x, into = c("pet", "sampSize"), "([^(]+)\\s+\\(([0-9]+).") | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Create labelled list of all active dataframes | |
my.list <- mget(ls(pattern="*_UMAC")) | |
# Use write.csv in a for loop, creating files for each and naming | |
# according to label (i.e. df name) | |
for (i in seq_along(my.list)){ | |
write.csv(my.list[i], paste(names(my.list)[i], ".csv"), col.names = TRUE) | |
} |
NewerOlder