-4
//function to enter .csv data
> data_entry <- function(NAME="filename.csv"){
+ dat <- read.csv(NAME)
+ }
> data_entry("data.csv")
> dat

When I enter this code, I get the following error: "object 'dat' not found" Where did I go wrong? P.S : I have placed "data.csv" in the required directory.

1

1 Answer 1

1

Objects created inside a function stay inside the function and are not exported into the global env, unless you return them, and assign the function result to a new name.

You should :

data_entry <- function(NAME="filename.csv"){
dat <- read.csv(NAME)
return(dat)
}

dat <- data_entry("data.csv")
dat
Sign up to request clarification or add additional context in comments.

1 Comment

@Sricharan glad to be of help :) Don't forget to accept the answer if you found what you were looking for ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.