File picking using pattern in R -



File picking using pattern in R -

this question has reply here:

r-project filepath concatenation 1 reply passing directory path parameter in r 1 reply

i have directory having multiple files starts 001.csv, 002.csv , on. want pick files in function pass argument function. ex.

myfiles<-function(x=1:30){ // should pick files starts 001.csv till 030.csv. }

i tried using pattern matching not sure how create pattern matching using variable consists of vectors. tried using paste function paste total file path giving me file name 1.csv , not 001.csv

tt<-function(dirname,type,nums=1:30){ filenames<-list.files(dirname) c<-nums myvector<-0 for(i in 1:length(c)){ myvector[i]<-paste(dirname,"/",c[i],".csv",sep="") #print(myvector[i]) }

}

one way able right names pad start of numbers 0s using formatc e.g.

paste0(formatc(seq(1:30), width = 3, format = "d", flag = "0"), ".csv")

r

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -