Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #setting package and directory
- library(plyr)
- library(stringr)
- setwd("/Users/macbook/Desktop/Project_Folder/File_folder1")
- #Creating a list of all the filenames:
- filenames <- list.files(path = "/Users/macbook/Desktop/Project_Folder/File_folder1")
- #creating a function to read csv and in the same time adding an additional column with the name of the file
- read_csv_filename <- function(filename)
- {
- ret <- read.csv(filename, header=TRUE, sep=",")
- ret$Source <- filename #EDIT
- ret
- }
- #importing
- import <- ldply(filenames, read_csv_filename)
- #making a copy of import
- data<-import
- #modifying the file name so it removes ".csv" and change the header
- data$Source<-str_sub(data$Source, end=-5)
- data[1,3]<-"date_expnb_pulsenb"
- t<-substr(data[1,3],1,3)
- head(data, n=10)
- #create a column with the experiment number, extracted from the file name
- data$expnb<-substr(data$Source, 10, 13)
- data$expnb<-as.numeric(data$expnb)
- head(data, n=10)
- tail(data, n=10)
- > head(data, n=10)
- Time Channel.A Source pulsenb expnb
- 1 (us) (A) expnb_pulsenb NA NA
- 2 -20.00200030 -0.29219970 20190409-0001_002 2 1
- 3 -20.00100030 -0.29219970 20190409-0001_002 2 1
- > tail(data, n=10)
- Time Channel.A Source pulsenb expnb
- 20800511 179.99199405 -0.81815930 20190409-0001_105 105 1
- 20800512 179.99299405 -0.81815930 20190409-0001_105 105 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement