Importing csv file to R

Greeting folks!
I am new to R and I want to study some data from a .csv file. I was told to make a scatter plot of two variables x against y to see their relationship.

  • I was wondering what is the first thing to get everything set up? Do I have to create a new folder and set a working dictionary first?
  • And then what function should I use to import my .csv to my dataset?
  • Note that the .csv folder has more than two columns so how can I specifically choose the two that I wanted?
    So much thanks!
    Sorry for so many questions, please forgive me I am very new to this :smiley:
  • I don't understand first question. may be directory, not dictionary.
    basically document directory is used to working directory unless you explicitly set it.
    so you can

    • work in document directory
      or
    • make directory
    • and move files
    • then set working directory to work.
  • to read csv file, I usually use read.csv function

  • of course you can do this,

tab = read.csv('your.csv')
# header(tab) will helpful.
tab[,c(1,3)] # this will call first and third column of csv file.

How do I plot a graph with only two variables? I have 12 variables in my .csv file but I only want to use two of them...

Regarding to the previous question:
I have imported my .csv using this,

my.data <- read.csv("data.csv" , header = T)

is that ok?

Thanks in advance!

If you are not familiar with R yet. it's good time to learn ggplot2.
which is awesome visualizing package

You can learn it from this link (https://ggplot2.tidyverse.org/).
I strongly recommend you to at least look up it.

Here are example articles for plot csv data with ggplot2


Or you can just plot them with this code

# assume you want to see column 1 and column 3.
my.data = read.csv("data.csv", header = T)
x = my.data[,1]
y = my.data[,3]

plot(x,y)

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.