Files लिखना
Files लिखना R से आपके results आपके computer पर save करता है, एक document खत्म करने के बाद save करने की तरह। आप एक data frame को एक CSV की तरह store कर सकते हैं जिसे दूसरे programs खोल सकें।
In this page:
Syntax
write.csv(df, "file.csv", row.names = FALSE)
Files लिखना
write.csv(df, "file.csv") एक data frame को एक CSV file में लिखता है, और row.names = FALSE आमतौर पर एक extra unnamed index column लिखने से बचने के लिए add होता है।
यह कहीं और इस्तेमाल के लिए R से processed data export करने का standard तरीका है। writeLines() plain text लिखने के लिए एक lower-level alternative है।
Note:
हमेशा write.csv() को row.names = FALSE pass करें जब तक आप specifically R का row index एक extra column की तरह written न चाहें।
उदाहरण: Writing Files
df <- data.frame(name = c("Alice", "Bob"), age = c(30, 25))
write.csv(df, "output.csv", row.names = FALSE)
contents <- readLines("output.csv")
print(contents)
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
row.names = FALSEभूल जाना, जो CSV में एक unwanted index column add करता है।- बिना notice किए एक existing file overwrite करना, क्योंकि
write.csvइसे silently replace करता है। - एक ऐसे folder में लिखना जो exist नहीं करता, जो
cannot open the connectionके साथ fail होता है।
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: