Output with different names

15 views
Skip to first unread message

Itzik

unread,
Dec 17, 2014, 8:51:50 AM12/17/14
to israel-r-...@googlegroups.com
שלום,
אשמח לקבל עזרה בכתיבת פונקציה אשר תקרא מספר קבצים סימולטנית, הנמצאים בתיקיה אחת, תבצעה פעולה מתמטית זהה על כל אחד מהקבצים בנפרד ואת התוצרים תשמור באותו השם של קובץ המקור + תוספת מסויימת. קבצים החדשים יוכנסו לתוך תיקיה אחרת.
אני משתמש בקבצי CSV.
הפורמט של שם הקובץ הוא קבוע: שם (מספר תווים שונה עבור כל שם) אך הסיומת זהה לכלל הקבצים למשל:
Name_CDD
 
 
בתודה מראש וחג שמח,
איציק

Jonathan Rosenblatt

unread,
Dec 18, 2014, 2:31:25 AM12/18/14
to israel-r-user-group
אני חושב שכל הכלים שתצטרך מפורטים בעזרה של  files
כמובן בסיוע קל של paste.

מקווה שזה עוזר.


--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-g...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
Jonathan Rosenblatt
www.john-ros.com

Liad Shekel

unread,
Dec 18, 2014, 3:06:11 AM12/18/14
to Israel R User Group
setwd("C:/.../dir_of_files")

# directory name 
# (the script assumes that the new directory is placed inside the working directory)
new_dir <- "my_name" 
 
addition_to_file<- "whatever"
list_of_files <- list.files()

for (file1 in list_of_files){
tbl <- read.csv(file1)

# apply your function - 'f'
results <- f(tbl) 

# remove .csv extension from file name
file1_nocsv <- unlist(strsplit(file1,".csv", fixed = TRUE)) 

# the name of the new file
new_file_name <- paste(new_dir,"/",file1_nocsv,"_",addition_to_file,".csv", sep = "") 

# write 'results' to 
write.csv( results, file = new_file_name )
}

:-)

Itzik

unread,
Dec 22, 2014, 5:44:14 AM12/22/14
to israel-r-...@googlegroups.com
הי ליעד
תודה רבה, זה עושה בדיוק את מה שאני צריך (למרות שאני מקבל הודעת שגיאה בסוף התהליך. הבעיה כנראה בפונקציה שלי).
חג שמח,
איציק
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
Jonathan Rosenblatt
www.john-ros.com

--
You received this message because you are subscribed to the Google Groups "Israel R User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to israel-r-user-group+unsub...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.


--
:-)
Reply all
Reply to author
Forward
0 new messages