I have a list containing rules for certain number of trials, such as rules[1] outputs set of 123 rules, rules[[2]] outputs set of 32 rules.Now, I have to get those numbers (123,32 ->number of rules)in a vector? It's not a string it's a List with items as Rules derived using apriori algorithm.
Asked
Active
Viewed 54 times
-4
-
Welcome to StackOverflow. Please be sure to read about providing a [minimal, complete, and verifiable example](http://stackoverflow.com/help/mcve) and have a look at making a [reproducible R example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). Images are generally not the way to share your example data. – Jota Jan 11 '16 at 07:18
-
1You may be looking for `lengths(thelist)` – Jota Jan 11 '16 at 07:22
1 Answers
1
We can use str_extract
library(stringr)
as.numeric(str_extract(thelist, '\\d+'))
#[1] 450 396
data
thelist <- list("set of 450 rules", "set of 396 rules")

akrun
- 874,273
- 37
- 540
- 662
-
1Thanks for ur time. The above code u have posted would definitely help me in the future – Sandesh Jan 11 '16 at 06:56