Take the 2-minute tour ×

I am a newbie to R.

I can successfully load my dataset into R-Studio, and I can see my dataset in the workspace. When I run the command summary(mydataset), I get the expected summary of all my variables.

However, when I run


I get the following warning message:

In data(mydataset) : data set ‘mydataset’ not found

I need to run the data() command as recommended in the fitLogRegModel() command, which is part of the PredictABEL package.

Does anybody have a hint on how I can specify mydataset as working dataset?

share|improve this question
add comment

migrated from stats.stackexchange.com Sep 6 '12 at 14:08


2 Answers

up vote 4 down vote accepted

You don't need to use the data command. You can just pass your data to the function

riskmodel <- fitLogRegModel(data=mydataset, cOutcome=2, 
     cNonGenPreds=3:10, cNonGenPredsCat=6:8, 
     cGenPreds=c(11, 13:16), cGenPredsCat=0)

The example uses data(ExampleData) so that it can make data that is in the package available to you. Since you already have your data, you don't need to load it.

share|improve this answer
GSee; Thank you, that helps. I was able to work on my dataset. –  2380 Sep 7 '12 at 14:03
GSee; Is there any way I can use the column header instead of specifying the column numbers. For instance: cOutcome=myoutcome, instead of cOutcome=2? That would help. Thanks! –  2380 Sep 9 '12 at 0:22
@2380, sure. Did you try? –  GSee Sep 9 '12 at 0:33
Yes, I tried for hours. The best solution I was able to find was to enter command attach(mydataset). After that, I was able to enter commands mean(age) and so on. However, I understand there are caveats regarding the attach commands, and I was wondering if there are safer and more efficient ways to do that. –  2380 Sep 9 '12 at 6:27
If mydataset is a data.frame, you can subset like this mydataset[["myoutcome"]] –  GSee Sep 9 '12 at 12:04
show 1 more comment

An alternative, although it has its drawbacks, is to use attach(mydataset). You can then refer to variables without a mydatdataset$ prefix. The main drawback, as far as I know (although I'd welcome the views of more expert R users) is that if you modify a variable after attaching, it is then not part of the dataset. This can cause confusion and lead to "gotchas". In any case, many expert R users counsel against the use of attach.

share|improve this answer
I would say that a bigger drawback is that you increase the risk of conflicts/masking. Consider if you have a vector in the global environment with the same name as a column in the attached data set, or you have 2 data sets attached with 1 or more columns having the same name. It is easy to get errors and warnings that are not obvious (lengths don't match), or worse yet, no error or warning but a result that is meaningless but looks reasonable. Best is to use the data argument in functions, the with or within functions are next best. –  Greg Snow Sep 6 '12 at 17:55
Thanks! That makes sense –  Peter Flom Sep 6 '12 at 18:01
Peter; thank you for sharing this alternative and its drawbacks. I appreciated it. –  2380 Sep 7 '12 at 14:06
add comment

Your Answer


