Thank you in advance for your help!
I made a function in R that returns a dataframe, say DF_Name
which have 4 columns, say harder
,better
,faster
,stronger
, and I just want to store this single dataframe in the Global Environment.
Here´s an extremely simplified version of the function:
daft_funct<-function()
{
DF_Name <- read.csv("D:/SomeFolder/DF_Data.csv",stringsAsFactors=FALSE)
return(DF_Name) # I want to fix this line here
}
And these are my unsuccessfully attemps to store it on .GlobalEnv
:
Without any knowledge:
return(DF_Name) # Just shows on screen
Attempt to see the whole dataframe, shows but doesn´t store:
View(DF_Name) # Shows on RStudio panel
Looking for help in StackOverflow and found this question. However it stores every single column of the data frame as separated values:
list2env(DF_name,.GlobalEnv) # Check if worked >ls() "better" "faster" "harder" "stronger"
Looking again for help in StackOverflow and found this other question. Which stores every single column of
DF_Name
again, but this time as separated data frames:list2env(lapply(DF_Name, as.data.frame),.GlobalEnv) # Check if worked >ls() "better" "faster" "harder" "stronger"
Trying to merge the dataframes from 4th attempt into a single one inside the function leads to the main problem again.
P.S.: I have intentionally omitted daft_funct
from ls()
output.