• 1 About this tutorial
    • 1.1 Download and install R and RStudio
    • 1.2 Getting familiar with RStudio
      • 1.2.1 Console vs. script
      • 1.2.2 Comments
      • 1.2.3 Packages
  • 2 Introduction to R
    • 2.1 Importing data
      • 2.1.1 Importing CSV files
      • 2.1.2 Setting your working directory
      • 2.1.3 Assigning data to objects
      • 2.1.4 Importing Excel files
      • 2.1.5 Inspecting the Airbnb dataset
      • 2.1.6 Importing data from Qualtrics
    • 2.2 Manipulating data frames
      • 2.2.1 Transforming variables
      • 2.2.2 Including or excluding and renaming variables (columns)
      • 2.2.3 Including or excluding observations (rows)
    • 2.3 The pipe operator
      • 2.3.1 One way to write code
      • 2.3.2 A better way to write code
    • 2.4 Grouping & summarizing
      • 2.4.1 Frequency tables
      • 2.4.2 Descriptive statistics
    • 2.5 Exporting (summaries of) data
    • 2.6 Graphs
      • 2.6.1 Scatterplot
      • 2.6.2 Jitter
      • 2.6.3 Histogram
      • 2.6.4 Log-transformation
      • 2.6.5 Plot the median
      • 2.6.6 Plot the mean
      • 2.6.7 Saving images
  • 3 Basic data analysis: analyzing secondary data
    • 3.1 Data
      • 3.1.1 Import
      • 3.1.2 Manipulate
      • 3.1.3 Merging datasets
      • 3.1.4 Recap: importing & manipulating
    • 3.2 Independent samples t-test
    • 3.3 One-way ANOVA
      • 3.3.1 Assumption: normality of residuals
      • 3.3.2 Assumption: homogeneity of variances
      • 3.3.3 The actual ANOVA
      • 3.3.4 Tukey’s honest significant difference test
    • 3.4 Linear regression
      • 3.4.1 Simple linear regression
      • 3.4.2 Correlations
      • 3.4.3 Multiple linear regression, without interaction
      • 3.4.4 Multiple linear regression, with interaction
      • 3.4.5 Assumptions
    • 3.5 Chi-squared test
    • 3.6 Logistic regression (optional)
      • 3.6.1 Measuring the fit of a logistic regression: percentage correctly classified
  • 4 Basic data analysis: experiments
    • 4.1 Data
      • 4.1.1 Import
      • 4.1.2 Manipulate
      • 4.1.3 Recap: importing & manipulating
    • 4.2 t-tests
      • 4.2.1 Independent samples t-test
      • 4.2.2 Dependent samples t-test
      • 4.2.3 One sample t-test
    • 4.3 Two-way ANOVA
      • 4.3.1 Following up with contrasts
    • 4.4 Moderation analysis: Interaction between continuous and categorical independent variables
      • 4.4.1 Spotlight analysis
    • 4.5 ANCOVA
    • 4.6 Repeated measures ANOVA
  • 5 Principal component analysis for perceptual maps (office dataset)
    • 5.1 Data
      • 5.1.1 Import
      • 5.1.2 Manipulate
      • 5.1.3 Recap: importing & manipulating
    • 5.2 How many factors should we retain?
    • 5.3 Principal components analysis:
      • 5.3.1 Factor loadings
      • 5.3.2 Loading plot and biplot
  • 6 Principal component analysis for perceptual maps (toothpaste dataset)
    • 6.1 Data
      • 6.1.1 Import
      • 6.1.2 Manipulate
      • 6.1.3 Recap: importing & manipulating
    • 6.2 How many factors should we retain?
    • 6.3 Principal component analysis
      • 6.3.1 Factor loadings
      • 6.3.2 Loading plot and biplot
  • 7 Cluster analysis for segmentation
    • 7.1 Data
      • 7.1.1 Import
      • 7.1.2 Manipulate
      • 7.1.3 Recap: importing & manipulating
    • 7.2 Cluster analysis
      • 7.2.1 Standardizing or not?
    • 7.3 Hierarchical clustering
    • 7.4 Non-hierarchical clustering
    • 7.5 Canonical LDA
  • 8 Conjoint analysis
    • 8.1 Data
      • 8.1.1 Import
      • 8.1.2 Manipulate
      • 8.1.3 Recap: importing & manipulating
    • 8.2 Design of experiments
    • 8.3 One respondent
      • 8.3.1 Estimate part-worths and importance weights
      • 8.3.2 Profiles: predicted utilities
    • 8.4 Many respondents
      • 8.4.1 Estimate part-worths and importance weights
      • 8.4.2 Profiles: predicted utilities
    • 8.5 Market simulation

R for marketing students

2.5 Exporting (summaries of) data

Sometimes you may want to export data or a summary of data. Let’s save our data or summary in a .csv file (in Excel, we can then convert it to an Excel file if we want):

# the first argument is the object you want to store, the second is the name you want to give the file (don't forget the .csv extension)
# use write_csv2 when you have a Belgian (AZERTY) computer, otherwise decimal numbers will not be stored as numbers

# store data
write_excel_csv(airbnb, "airbnb.csv")
write_excel_csv2(airbnb, "airbnb.csv") 

# store summary
write_excel_csv(airbnb.summary, "airbnb_summary.csv")
write_excel_csv2(airbnb.summary, "airbnb_summary.csv")

The file will be saved in your working directory.