Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to Replicate "R for Beginners" Example

Tags:

r

I've searched around, but can't figure this one out guys. I'm a total noob to R and am learning from scratch through "R for Beginners"

Barely into it, pg. 6, I cannot replicate their sample. In trying to explain "max.level", they show...

> name <- "Carmen"; n1 <- 10; n2 <- 100; m <- 0.5
> M <- data.frame(n1, n2, m)

> ls.str(pat = "M")
M : ‘data.frame’: 1 obs. of 3 variables:
$ n1: num 10
$ n2: num 100
$ m : num 0.5

> ls.str(pat="M", max.level=-1)
M : ‘data.frame’: 1 obs. of 3 variables:

but in R I get...

> name <- "Carmen"; n1 <- 10; n2 <- 100; m <- 0.5
> M <- data.frame(n1, n2, m)

> ls.str(pat = "M")
M : 'data.frame':       1 obs. of  3 variables:
 $ n1: num 10
 $ n2: num 100
 $ m : num 0.5

> ls.str(pat="M", max.level=-1)
Error in ls.str(pat = "M", max.level = -1) : 
  unused argument (max.level = -1)

I have no idea what i did wrong or how to fix it. Is there a typo in the guide? Is there some library I haven't loaded properly?

Help much appreciated!

like image 644
Jonathan L S Avatar asked Apr 04 '16 04:04

Jonathan L S


1 Answers

Not surprising. The reference you use is in 2005. R has changed (a lot!!!). There is no longer an argument max.level for function ls.str. I suggest you go for ?ls.str to catch up for the update.

If you want examples, check the bottom of that help page.

You really should use the latest R documentation at https://cran.r-project.org/. This is kept up to date. The "introduction to R" is pretty good for starters, with moderate length. Have fun!


update

A quick way to check what arguments a function has is to use function args. For example, args(ls.str).

The error message from R is very informative. So whenever you see "unused arguments", you should check whether you have passed arguments correctly.

I believe in 2005, R is still in version R-2.**. Because when I picked up R at 2011, it was still R-2.14.**. But now R is in R-3.**. From version 2** to version 3**, R kernel has changed a lot.

like image 130
Zheyuan Li Avatar answered Sep 24 '22 14:09

Zheyuan Li