← Back to R Course | Chapter 8: Data Manipulation | Lesson 2 of 7

Files लिखना

Files लिखना R से आपके results आपके computer पर save करता है, एक document खत्म करने के बाद save करने की तरह। आप एक data frame को एक CSV की तरह store कर सकते हैं जिसे दूसरे programs खोल सकें।

In this page:

  1. Files लिखना
Syntax
r
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

markup
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)
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. #}
आम गलतियां
  1. row.names = FALSE भूल जाना, जो CSV में एक unwanted index column add करता है।
  2. बिना notice किए एक existing file overwrite करना, क्योंकि write.csv इसे silently replace करता है।
  3. एक ऐसे folder में लिखना जो exist नहीं करता, जो cannot open the connection के साथ fail होता है।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.