Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating R dataset

Tags:

r

I want to create dataset in R so that I load into R session as follows:

data(mydatasetname)

I tried following:

values<- read.table("mydatasetname.txt") 
save(values,file="value.rda")

but when I type following command to load data:

data(values)

Warning message: In data(values) : data set ‘values’ not found

Can anybody help?

Nitin

like image 708
nit Avatar asked Nov 30 '25 22:11

nit


1 Answers

I suspect load may be what you're after though I'm not sure. If you load the data in directly there's no need to make the call to data as in:

mtcars2 <- mtcars                             #rename mtcars to mtcars2
save(mtcars2, file="mtcars2.rda")             #save mtcars2 
rm(mtcars2)                                   #remove from envir
mtcars2                                       #gone : (
load("mtcars2.rda")                           #load mtcars2 
mtcars2                                       #and you're back : )

Now you only need to use load(mtcars2.rda) from now on and your data is there.

If you want to use data() you may have to create a package with your data and load the package and then use data though I'm not 100% sure on this.

like image 147
Tyler Rinker Avatar answered Dec 03 '25 12:12

Tyler Rinker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!