Re: [R] importing multiple file form folder
Thanks for reply Rui, this is not exactly what i need. The way you proposed i get the data structured like this : Length, TempAtLocation1, TempAtLocation2TempAtLocationN What i'd like is to actuall get the data from each file in Columns, but they should be binded in rows in one table...something like this : Length, Date(or the name of each file), Temperature . . file 1 . . . . . file 2 . . . . . file 3 . . . . . file N . . . In that way i would have only three columns, and each 970 inputs (rows) the values woud represent temperature at different date. Any ideas? -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4632925.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Thanks for reply Rui, this is not exactly what i need. The way you proposed i get the data structured like this : Length, TempAtLocation1, TempAtLocation2TempAtLocationN What i'd like is to actuall get the data from each file in Columns, but they should be binded in rows in one table...something like this : Length, Date(or the name of each file), Temperature . . file 1 . . . . . file 2 . . . . . file 3 . . . . . file N . . . In that way i would have only three columns, and each 970 inputs (rows) the values woud represent temperature at different date (meaning imported column from a new file). Any ideas? -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4632927.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Thanks for reply Rui, this is not exactly what i need. The way you proposed i get the data structured like this : Length, TempAtLocation1, TempAtLocation2TempAtLocationN What i'd like is to actuall get the data from each file in Columns, but they should be binded in rows in one table...something like this : Length, Date(or the name of each file), Temperature . . file 1 . . . . . file 2 . . . . . file 3 . . . . . file N . . . In that way i would have only three columns, and each 970 inputs (rows) the values woud represent temperature at different date (meaning imported column from a new file). Any ideas? -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4632929.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
I am very sorry, but i dont know how it got posted three times! -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4632931.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Hello, Try the following example. #install.packages(reshape2) library(reshape2) d - data.frame(D=Sys.Date()+1:5, Temp1=1:5, Temp2=6:10, Temp3=11:15) d dm - melt(d, id=(D)) dm If this seems familiar, then in your it should be id=c(Length, Date) if Date already is a data.frame column. Hope this helps, Rui Barradas Em 10-06-2012 10:21, mpavlic escreveu: Thanks for reply Rui, this is not exactly what i need. The way you proposed i get the data structured like this : Length, TempAtLocation1, TempAtLocation2TempAtLocationN What i'd like is to actuall get the data from each file in Columns, but they should be binded in rows in one table...something like this : Length, Date(or the name of each file), Temperature . . file 1 . . . . . file 2 . . . . . file 3 . . . . . file N . . . In that way i would have only three columns, and each 970 inputs (rows) the values woud represent temperature at different date (meaning imported column from a new file). Any ideas? -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4632929.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Hi again all, @Rui, melt did the trick. Thanks! I managed to make this thing work somehow. ABellow is the script for this : setwd(C:/Users/mpavlic/Desktop/HE Krsko/HEK/FOC/Data/Jun/DDF) library(reshape2) library(sqldf) #imena datotek txt_files = list.files(pattern = '*.ddf'); flist-txt_files flistNew - sub(^channel 1 ([0-9 ]+).*, \\1, flist) flistNew -c(D,flistNew) # koordinate posamezne lokacije vzdolž FOC coordinate-read.csv(coordinate_linija1.csv, sep=;, dec=.)[,2:4] D-seq(1,970,by=1) coordinate-(cbind(D,coordinate)) #dolžina vzdolž FOC #Length - read.table(flist[1], skip=917, nrows=970)[, 1] Temp - do.call(cbind, lapply(flist, function(x) read.table(x, skip=917, nrows=970)[, 2])) Temp1-as.data.frame(cbind(D,Temp)) colnames(Temp1)-flistNew # zdruzi v tableo, tako da so temperature za posameni file po vrsticah dm - melt(Temp1, id=(D)) dm -data.frame(X=11.11, Y=11.11, dolzina=11.11, dm) But i have another problem... Is it possible to trnasform the names of each file which are listed in the variable txt_files to official R DateTime format? For example : so that this : channel 1 20120601 003507 1.ddf would be saved like this 2012-06-07 00:35:07 Thanks for the help -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4632942.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Hello, Try x - channel 1 20120601 003507 1.ddf search - ^channel [0-9]+ ([0-9]+ [0-9]+) .+$ replace - \\1 as.POSIXct(sub(search, replace, x), format=%Y%m%d %H%M%S) If this doesn't make it, use 'gsub', not 'sub'. Note that as.POSIXct makes use of time zones. See ?as.POSIXct and set the argument accordingly. Hope this helps, Rui Barradas Em 10-06-2012 18:01, mpavlic escreveu: Hi again all, @Rui, melt did the trick. Thanks! I managed to make this thing work somehow. ABellow is the script for this : setwd(C:/Users/mpavlic/Desktop/HE Krsko/HEK/FOC/Data/Jun/DDF) library(reshape2) library(sqldf) #imena datotek txt_files = list.files(pattern = '*.ddf'); flist-txt_files flistNew - sub(^channel 1 ([0-9 ]+).*, \\1, flist) flistNew -c(D,flistNew) # koordinate posamezne lokacije vzdolž FOC coordinate-read.csv(coordinate_linija1.csv, sep=;, dec=.)[,2:4] D-seq(1,970,by=1) coordinate-(cbind(D,coordinate)) #dolžina vzdolž FOC #Length - read.table(flist[1], skip=917, nrows=970)[, 1] Temp - do.call(cbind, lapply(flist, function(x) read.table(x, skip=917, nrows=970)[, 2])) Temp1-as.data.frame(cbind(D,Temp)) colnames(Temp1)-flistNew # zdruzi v tableo, tako da so temperature za posameni file po vrsticah dm - melt(Temp1, id=(D)) dm -data.frame(X=11.11, Y=11.11, dolzina=11.11, dm) But i have another problem... Is it possible to trnasform the names of each file which are listed in the variable txt_files to official R DateTime format? For example : so that this : channel 1 20120601 003507 1.ddf would be saved like this 2012-06-07 00:35:07 Thanks for the help -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4632942.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Thank Rui, as always your posts did the trick. Thanks, m -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4632948.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Hi all, i managed to (with the help of most posts here) using bellow code : setwd(C:/Users/mpavlic/Desktop/test) txt_files = list.files(pattern = '*.ddf'); flist-txt_files flistNew - sub(^channel 1 ([0-9 ]+).*, \\1, flist) coordinate-read.csv(coordinate_linija1.csv, sep=;, dec=.)[,2:4] Length - read.table(flist[1], skip=917, nrows=970)[, 1] Temp - do.call(cbind, lapply(flist, function(x) read.table(x, skip=917, nrows=970)[, 2])) colnames(Temp) - paste(flistNew, seq_len(ncol(Temp)), sep=.) result - cbind(Length=Length, coordinate, Temp) ...join all files in one folder in one big table. But the merging here is done by columns as seen in attachment-asColumns.csv (so that every column form certain file is added to the table result as a column). For better reperesentation of data I would now need data to be added as rows in a table, with corresponding name of the file as a value in column. Resulting table should look something like in an attached file asRows.csv. Is that possible? Hope i exaplined it ok, because it's a bit difficult. Thanks for any idea http://r.789695.n4.nabble.com/file/n4632909/asColumns.csv asColumns.csv http://r.789695.n4.nabble.com/file/n4632909/asRows.csv asRows.csv -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4632909.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Hello, 'cbind' means column bind and 'rbind', row bind. So, apparently, all you have to do is replace one letter. ONLY in the do.call, it will surelly do what you want, my only doubt is with cbinding the Length column, it should recycle the values. Hope this helps, Rui Barradas Em 09-06-2012 23:25, mpavlic escreveu: Hi all, i managed to (with the help of most posts here) using bellow code : setwd(C:/Users/mpavlic/Desktop/test) txt_files = list.files(pattern = '*.ddf'); flist-txt_files flistNew - sub(^channel 1 ([0-9 ]+).*, \\1, flist) coordinate-read.csv(coordinate_linija1.csv, sep=;, dec=.)[,2:4] Length - read.table(flist[1], skip=917, nrows=970)[, 1] Temp - do.call(cbind, lapply(flist, function(x) read.table(x, skip=917, nrows=970)[, 2])) colnames(Temp) - paste(flistNew, seq_len(ncol(Temp)), sep=.) result - cbind(Length=Length, coordinate, Temp) ...join all files in one folder in one big table. But the merging here is done by columns as seen in attachment-asColumns.csv (so that every column form certain file is added to the table result as a column). For better reperesentation of data I would now need data to be added as rows in a table, with corresponding name of the file as a value in column. Resulting table should look something like in an attached file asRows.csv. Is that possible? Hope i exaplined it ok, because it's a bit difficult. Thanks for any idea http://r.789695.n4.nabble.com/file/n4632909/asColumns.csv asColumns.csv http://r.789695.n4.nabble.com/file/n4632909/asRows.csv asRows.csv -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4632909.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Hi Jim, thanks for that, works perfectly. m -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4631798.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Hi Sarah, I can not for the life of me understand what was wrong with my post?!? Can you please explain, so that i will not make the same mistake again? Regards, m -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4631734.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Hi Rui, Thanks a lot, it works like I wanted. I am sorry about my late response though... Is it possible to get the name of the file (Channe 1. ) as a name of the column in the resulting table (dataframe)? Many thanks, m -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4631735.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Hi again Rui, i got the column names settled like this : colnames(Temp) - paste(flist, seq_len(ncol(Temp)), sep=.) Thanks again, m -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4631737.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Just one more thing ... my colnames are as follows : c(channel 1 20120509 153744 1.ddf, channel 1 20120509 154744 1.ddf, channel 1 20120509 155744 1.ddf, channel 1 20120509 160744 1.ddf, channel 1 20120509 161744 1.ddf, channel 1 20120509 162744 1.ddf,...) How would i get just the numbers after channel 1 as name of the column? For example, 2012205009 153744 instead of channel 1 201220509 153744... Thanks, m -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4631753.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Here is how to get the number: x - c(channel 1 20120509 153744 1.ddf, channel 1 20120509 154744 1.ddf, + channel 1 20120509 155744 1.ddf, channel 1 20120509 160744 1.ddf, + channel 1 20120509 161744 1.ddf, channel 1 20120509 162744 1.ddf) # get the number xNew - sub(^channel 1 ([0-9 ]+).*, \\1, x) # notice the space after the '9' xNew [1] 20120509 153744 1 20120509 154744 1 20120509 155744 1 20120509 160744 1 [5] 20120509 161744 1 20120509 162744 1 On Tue, May 29, 2012 at 3:41 PM, mpavlic matevz.pav...@gi-zrmk.si wrote: Just one more thing ... my colnames are as follows : c(channel 1 20120509 153744 1.ddf, channel 1 20120509 154744 1.ddf, channel 1 20120509 155744 1.ddf, channel 1 20120509 160744 1.ddf, channel 1 20120509 161744 1.ddf, channel 1 20120509 162744 1.ddf,...) How would i get just the numbers after channel 1 as name of the column? For example, 2012205009 153744 instead of channel 1 201220509 153744... Thanks, m -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4631753.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- Jim Holtman Data Munger Guru What is the problem that you are trying to solve? Tell me what you want to do, not how you want to do it. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
On May 29, 2012, at 10:56 AM, mpavlic wrote: Hi Sarah, I can not for the life of me understand what was wrong with my post?!? Can you please explain, so that i will not make the same mistake again? She asked you to read the Posting Guide. It _still_ appears you have not done so. Please stop posting without context. Regards, m -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4631734.html Sent from the R help mailing list archive at Nabble.com. Nabble is NOT Rhelp and it is not NOT Rhelp archive. PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. -- David. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] importing multiple file form folder
Hi all, I have a set of files (which is growing) in a folder. The files are text files... The form of files is such : ...with numbers for Length (m) going up to 2000 ... Anyway...i just need the data from first two columns (length (m) and Temperature (C)), and no data before that... This Lenght (m) values are always the same. My final dataset should lokk like this : column 1 as Length(m) ; column 2 as Temperature from first file ; column3 as temperature from second file...and so on... I know how to import this manualy, but can seem to find a way to automate it...the problem is that the amout of files will be growing for quite quite some time, so automation is necessary. Any help is greatly apreciated. m -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
I managed to sort something out with a for loop, but it's till not working ok... What it does is it loops through all files in the folder, it imports each file from line 763 on. Than it just takes the second column (Temprerature) and binds the columns (cbind). BUT it just binds the values of the last file instead of EACH file. Any ideas? Attached are two files for easier understanding... thanks, m http://r.789695.n4.nabble.com/file/n4631640/channel_1_20120509_153744_1.ddf channel_1_20120509_153744_1.ddf http://r.789695.n4.nabble.com/file/n4631640/channel_1_20120509_154744_1.ddf channel_1_20120509_154744_1.ddf -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4631640.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Sure, I have lots of ideas, mostly involving you overwriting your results with each iteration. But unless you post your code to the the list, I'll never know if my ideas are right. Please read the posting guide. Using the Nabble interface does not exempt you from posting manners. Sarah On Mon, May 28, 2012 at 5:25 PM, mpavlic matevz.pav...@gi-zrmk.si wrote: I managed to sort something out with a for loop, but it's till not working ok... What it does is it loops through all files in the folder, it imports each file from line 763 on. Than it just takes the second column (Temprerature) and binds the columns (cbind). BUT it just binds the values of the last file instead of EACH file. Any ideas? Attached are two files for easier understanding... thanks, m http://r.789695.n4.nabble.com/file/n4631640/channel_1_20120509_153744_1.ddf channel_1_20120509_153744_1.ddf http://r.789695.n4.nabble.com/file/n4631640/channel_1_20120509_154744_1.ddf channel_1_20120509_154744_1.ddf -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4631640.html Sent from the R help mailing list archive at Nabble.com. __ -- Sarah Goslee http://www.functionaldiversity.org __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Hi, if you're on a mac, I would recommend Automator. If you're on unix I would recommend a handy bash script with regex. And on windows.. I don't know.. you could do regex in R, couldn't you? Am 28.05.2012 um 21:02 schrieb mpavlic: Hi all, I have a set of files (which is growing) in a folder. The files are text files... The form of files is such : ...with numbers for Length (m) going up to 2000 ... Anyway...i just need the data from first two columns (length (m) and Temperature (C)), and no data before that... This Lenght (m) values are always the same. My final dataset should lokk like this : column 1 as Length(m) ; column 2 as Temperature from first file ; column3 as temperature from second file...and so on... I know how to import this manualy, but can seem to find a way to automate it...the problem is that the amout of files will be growing for quite quite some time, so automation is necessary. Any help is greatly apreciated. m -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
Hello, I've named your file 'file1.txt' and with readLines(file1.txt) saw 25 lines, then a header, then a table of tab separated values. The header is full of blanks, such as the ones in 'length (m)' and 'temperature (°C)', making it impratical. So if 'flist' is your list of files, try the following. flist - file1.txt # First, read only one and keep only the lengths column Length - read.table(flist[1], skip=26)[, 1] # Then read the temperatures from all files and cbind them into a matrix Temp - do.call(cbind, lapply(flist, function(x) read.table(x, skip=26)[, 2])) # Tidy up colnames(Temp) - paste(Temperature, seq_len(ncol(Temp)), sep=.) # And put it all together result - cbind(Length=Length, Temp) Hope this helps, Rui Barradas Em 28-05-2012 21:02, mpavlic escreveu: Hi all, I have a set of files (which is growing) in a folder. The files are text files... The form of files is such : ...with numbers for Length (m) going up to 2000 ... Anyway...i just need the data from first two columns (length (m) and Temperature (C)), and no data before that... This Lenght (m) values are always the same. My final dataset should lokk like this : column 1 as Length(m) ; column 2 as Temperature from first file ; column3 as temperature from second file...and so on... I know how to import this manualy, but can seem to find a way to automate it...the problem is that the amout of files will be growing for quite quite some time, so automation is necessary. Any help is greatly apreciated. m -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] importing multiple file form folder
I believe my already posted solution works. I've just tried it with your examples. url - c(http://r.789695.n4.nabble.com/file/n4631640/channel_1_20120509_153744_1.ddf;, http://r.789695.n4.nabble.com/file/n4631640/channel_1_20120509_154744_1.ddf;) flist - url And the rest is exactly the same. But, ok, I'll post it again. Length - read.table(flist[1], skip=26)[, 1] Temp - do.call(cbind, lapply(flist, function(x) read.table(x, skip=26)[, 2])) colnames(Temp) - paste(Temperature, seq_len(ncol(Temp)), sep=.) result - cbind(Length=Length, Temp) head(result) Length Temperature.1 Temperature.2 [1,] -747.200 325.138 800.000 [2,] -746.18518.874 -200.000 [3,] -745.171 488.420 800.000 [4,] -744.15669.484 -78.434 [5,] -743.142 -70.252 129.180 [6,] -742.127 -200.000 -200.000 Em 28-05-2012 22:25, mpavlic escreveu: I managed to sort something out with a for loop, but it's till not working ok... What it does is it loops through all files in the folder, it imports each file from line 763 on. Line 763 on? I'm off by 737... Than it just takes the second column (Temprerature) and binds the columns (cbind). BUT it just binds the values of the last file instead of EACH file. Any ideas? Attached are two files for easier understanding... If you ask for help, read the answers, please, the second file changed nothing. (Nor it hurts to check what was posted before.) thanks, m http://r.789695.n4.nabble.com/file/n4631640/channel_1_20120509_153744_1.ddf channel_1_20120509_153744_1.ddf http://r.789695.n4.nabble.com/file/n4631640/channel_1_20120509_154744_1.ddf channel_1_20120509_154744_1.ddf -- View this message in context: http://r.789695.n4.nabble.com/importing-multiple-file-form-folder-tp4631637p4631640.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Rui Barradas __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.