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.
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 at 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.
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 at 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.
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_00001.ddf channel_1_20120509_153744_00001.ddf http://r.789695.n4.nabble.com/file/n4631640/channel_1_20120509_154744_00001.ddf channel_1_20120509_154744_00001.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.
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.
Just one more thing ... my colnames are as follows : c("channel 1 20120509 153744 00001.ddf", "channel 1 20120509 154744 00001.ddf", "channel 1 20120509 155744 00001.ddf", "channel 1 20120509 160744 00001.ddf", "channel 1 20120509 161744 00001.ddf", "channel 1 20120509 162744 00001.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.
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.