Help Reading File

Hello, so I am working on a problem and need some help with what I am trying to accomplish

Background, trying to merge 2 files (CSV) the way I have been told to do it is:
wdir <- "C:\Users\(User name)\Documents\(File Name)"
which works and sets the WD

However when I try to read the file with:
PartA_IV <- read.csv('P1A_IV_sample.csv', header=TRUE)
It says no such directory exists, 2 file names are P1A_IV_sample.csv, P1A_DV_sample.csv

Here you are defining an object called wdir which contains a character string that represents your file path but you are not setting the working directory, so if your actual working directory doesn't contain the csv files, you are simply specifying the wrong path to the file.

You can set the working directory by using the setwd() function or use an absolute path to your files, but this is broadly considered a bad practice (because it affects the portability and reproducibility of your code), it is better to use a "project" oriented workflow

Okay so Kind of step by step, Im very new to R:
New Project-->New Directory--->New Project-->
And for Directory name do I put in the file?

I put: the file name then made it a subdirectory of where the two files are located, but then it gave me same error:
image
That is what it looks like

You need to use setwd() to actually change the location of your working directory.

You have to put the name of your project (whatever you want to call it), it is going to create a folder of the same name and you should put inside it, everything you need for your project, including data files. Once a project is active (with the "Open Project" button), you can refer to any file inside it just by name without worrying what its file path is, even if you move the project folder somewhere else or copy it to another computer (on active projects paths are relative to project home folder).

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.