Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Machine Learning by (17.6k points)

How to select a random element from a list in R?

1 Answer

0 votes
by (41.4k points)

R Programming is used in a variety of aspects. Studying Machine Learning Course and making it easy is one of its prime benefits. R Programming is somewhat related to Machine Learning Tutorial as well. If we are having a list suppose a<- c(2,3,8,9,5) and if we want to select a random element from this list, then we will use sample ( a,1). This will give us a random element from the list a.

If your vector length is 1, then use the below line of code, otherwise, it will show unusual behavior :

a[sample(1:length(a),1)]

Now, if you want to get more programming experience in R then you must watch this video tutorial:

 

Related questions

Browse Categories

...