Export your data from R

Overview

Teaching: 20 min
Exercises: 20 min
Questions
  • How to export my tidy file?

Objectives
  • Export a tidy file from R

Work.table Command to export your data from R

We are aiming to output the .csv file we have tidied from last episode.

#Save the exported file in Downloads
setwd("Downloads")
#Read your data from Downloads
xx <- read_csv("Downloads/DayToFlower.csv")
xx <- read_xlsx("Downloads/DayToFlower.xlsx", sheet = "DayToFlower")
xx<-na.omit(xx)
yy <- xx %>%
  group_by(Name, Location) %>%
  summarise(Mean_DTF = round(mean(DTF),1)) %>% 
  arrange(Location)
yy
#Your coad
yy <- yy %>% spread(key = Location, value = Mean_DTF)
yy
yy <- yy %>% gather(key = TraitName, value = Value, 2:4)
yy
yy <- yy %>% spread(key = Name, value = Value)
yy
write.table(yy,file="DataToExport.csv", sep=",")

Screenshot of main code listing

Now your DataToExport.csv is saved in Downloads.

Screenshot of main code listing

To remove row name

write.table(yy,file="DataToExport.csv", row.names=F, sep=",")

Screenshot of main code listing

Key Points

  • Make sure to indicate where you would like to see the exported file.

  • Set row.names=F to remove unwanted row names while exporting your file.