0
我的最終目的是隻保留時間和濃度的列,但在我跳過頂部的所有行之前,我想保留日期「9/12/2017」(我將添加到後面的時間列)。年的兩個數字成爲逗號
有一個討厭的「樣品1評論:」最後,我需要擺脫它。最大的問題是,當我試圖保存日期時,它沒有出現「9/12/2017」,而是「9/12/17 ,,」。我不知道爲什麼會這樣,它最終可能會受到評論線的影響,兩年的數字變成了逗號。
Sample File E:\CPC 091217\091217CPC3.C07
Model 3007
Sample # 1
Start Date 9/12/2017
Start Time 10:29:57
Sample Length 4:14:37
Averaging Interval (secs) 1
Title
Instrument ID 3007-03160001 3.1
Instrument Errors None
Time Concentration (#/cm³)
10:29:58 4224
10:29:59 97323
10:30:00 14590
10:30:09 73716
10:30:10 70779
10:30:11 60642
10:30:12 56171
.........
Comment for Sample 1:
我想什麼是
cpcFile = choose.files(default = "", caption = "
SELECT THE CPC.csv FILE ",
multi = FALSE, filters = Filters[c("txt", "All"),],
index = nrow(Filters))
cpcData <- read.csv(cpcFile, skip = 16)
#helps get rid of the comment line,it works
cpcData<-cpcData[- grep("Comment", cpcData$Time),]
#however,the P6 shows "9/12/17,,"instead of " "9/12/2017"
K=readLines(cpcFile, n = 5) # read first 5 lines
header=K[[5]] # read only the date and time
P6= substr(header, 12, 25)
期望:
Time Concentration (#/cm³)
10:29:58 9/12/2017 4224
10:29:59 9/12/2017 97323
10:30:00 9/12/2017 14590
10:30:09 9/12/2017 73716
........
和P6應該是2017年9月12日首先,非常感謝!
一些靈感:https://stackoverflow.com/a/37665045/2204410 – Jaap