Good morning. Very new to programming and R. I'm working on a research project and my partner (who is also new at programming) is gathering data with php and creating tables and I need to take each table and format it and create a new file with the date of the data obs in the name.
The tables have a fixed number of columns, but a random number of rows. I did the first directory of tables manually, which wasn't too bad, but I'd like to learn how to do it in R. Below is the code I'm using to format the tables.
setwd("/dir1")
botg<-read.csv(file = "6_30_botg.csv", header = TRUE, sep = ",", colClasses="character")
##read directory of files in
##assign each table to new variable
##create a botg <- function() to breakdown each table and report new table
botg1<-botg[,c(3, 4, 5, 6)]
botg1$price <- str_replace_all(string=botg1$price, pattern="\\$", replacement="")
botg1[, 5:9] <- colsplit(botg1$price, pattern=",", c("Price1", "Price2", "Price3", "Price4", "Price5"))
botg1$shipping <- str_replace_all(string=botg1$shipping, pattern="\\$", replacement="")
botg1$shipping <- str_replace_all(string=botg1$shipping, pattern="Shipping:", replacement="")
botg1[, 10:14] <- colsplit(botg1$shipping, pattern=",", c("Shipping1", "Shipping2", "Shipping3", "Shipping4", "Shipping5"))
botg1[, 15:19] <- colsplit(botg1$quantity, pattern=",", c("Quantity1", "Quantity2", "Quantity3", "Quantity4", "Quantity5"))
botg1$Quantity1 <- as.numeric(botg1$Quantity1)
botg1$Quantity2 <- as.numeric(botg1$Quantity2)
botg1$Quantity3 <- as.numeric(botg1$Quantity3)
botg1$Quantity4 <- as.numeric(botg1$Quantity4)
botg1$Quantity5 <- as.numeric(botg1$Quantity5)
botg1$price <- NULL
botg1$shipping <- NULL ##removes original columns from table
botg1$quantity <- NULL
setwd("/dir2")
write.csv(botg1, file="2014-06-30.csv") ##need to automate write.csv
My immediate roadblock is reading in the directory of csv and assigning each table to a new variable. Any suggestions or hints would be awesome!