Re: [R] how to read this kind of csv in R?

2019-10-07 Thread Rui Barradas
Hello, OK, I had some spare time. Try readCSVFile <- function(filename){ lns <- readLines(filename) lns <- lns[sapply(lns, nchar) > 0] lns <- gsub(" ", "", lns) lns <- sub(";$", "", lns) i_title <- grep("[[:alpha:]]", lns) blocks <- lapply(seq_along(i_title)[-1], function(i){

Re: [R] how to read this kind of csv in R?

2019-10-07 Thread pauluo via R-help
The csv file is exported from Windows (dos format), so the line break is different from Unix. 在 星期一, 07 十月 2019 01:18:54 -0700 撰写 > I am mad about importing this strange csv format type. > > The real csv has been attached now. The raw data points are huge. > > Many thanks. >

Re: [R] how to read this kind of csv in R?

2019-10-06 Thread Rui Barradas
Hello, It is not clear if all files have * a first block with just one data line * all other blocks with as many rows as the numbers in that first data line. If yes, maybe something like this? lns <- readLines("strange.csv") lns <- lns[sapply(lns, nchar) > 0] lns <- sub(",$", "", lns) i_title

Re: [R] how to read this kind of csv in R?

2019-10-06 Thread Duncan Murdoch
On 06/10/2019 8:23 a.m., vod vos wrote: The problem is aa, bb and cc all in a single csv file contains no blank line. So what steps do you need, and which of them do you need help with? Duncan Murdoch The single csv file like list output. aa(cm) 1, 2 , 3, bb(mm) 1, 2, 3, 4, 5, 6,

Re: [R] how to read this kind of csv in R?

2019-10-06 Thread vod vos via R-help
The problem is aa, bb and cc all in a single csv file contains no blank line. The single csv file like list output. aa(cm) 1, 2 , 3, bb(mm) 1, 2, 3, 4, 5, 6, 7, 8, 9, cc(mm) 3, 4, 5, 7, 5, 9, 6, 5, 8, 在 星期日, 06 十月 2019 05:08:41 -0700 Duncan Murdoch 撰写 > On 06/10/2019 7:

Re: [R] how to read this kind of csv in R?

2019-10-06 Thread Duncan Murdoch
On 06/10/2019 7:29 a.m., vod vos via R-help wrote: I got hundreds of csv files. The real formats in each csv file are as follows: aa(cm) 1, 2 , 3, bb(mm) 1, 2, 3, 4, 5, 6, 7, 8, 9, cc(mm) 3, 4, 5, 7, 5, 9, 6, 5, 8, How can I use read.table or read.csv to convert the csv files to a tidy data f

[R] how to read this kind of csv in R?

2019-10-06 Thread vod vos via R-help
I got hundreds of csv files. The real formats in each csv file are as follows: aa(cm) 1, 2 , 3, bb(mm) 1, 2, 3, 4, 5, 6, 7, 8, 9, cc(mm) 3, 4, 5, 7, 5, 9, 6, 5, 8, How can I use read.table or read.csv to convert the csv files to a tidy data frame format as follow: aa, bb, cc 1, 1, 3 1, 2, 4 1