Export Data to TXT in R: Step-by-Step

In R language, you can save data as a txt file using the write.table() function. Here is a simple example:

# 创建一个示例数据框
data <- data.frame(
  ID = c(1, 2, 3, 4, 5),
  Name = c("Alice", "Bob", "Charlie", "David", "Eve"),
  Age = c(25, 30, 35, 40, 45)
)

# 将数据保存为txt文件
write.table(data, "data.txt", sep = "\t", row.names = FALSE)

In the example above, we first created a data frame containing columns for ID, Name, and Age. We then used the write.table() function to save the data as a txt file named “data.txt”, with tabs as the delimiter. Setting row.names = FALSE means that row indexes are not saved. You can adjust the file name and delimiter as needed.

bannerAds