[R] importing multiple file form folder

Rui Barradas ruipbarradas at sapo.pt
Sun Jun 10 19:17:47 CEST 2012


Hello,

Try

x <- "channel 1 20120601 003507 00001.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 00001.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 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.
>



More information about the R-help mailing list