Slicing a list using an index vector in r

0 votes
How to slice a list using an index vector in R?
Oct 9, 2019 in Data Analytics by anonymous
• 3,450 points
10,726 views

1 answer to this question.

0 votes
Use index within [] and provide an index. For a group of index use c().

> x = list(c(1:5),6,7,letters[1:3],"x",LETTERS[1:5])

> x[2]
[[1]]
[1] 6

> x[2:4]
[[1]]
[1] 6

[[2]]
[1] 7

[[3]]
[1] "a" "b" "c"

> x[c(1,3)]
[[1]]
[1] 1 2 3 4 5

[[2]]
[1] 7
answered Nov 2, 2019 by Cherukuri
• 33,030 points

Related Questions In Data Analytics

0 votes
2 answers

R function for finding the index of an element in a vector?

The function match works on vectors : x <- sample(1:10) x # ...READ MORE

answered Dec 12, 2020 in Data Analytics by Rajiv
• 8,870 points
56,633 views
+1 vote
1 answer

How to convert a list of dataframes in to a single dataframe using R?

You can use the plyr function: data <- ...READ MORE

answered Apr 14, 2018 in Data Analytics by Sahiti
• 6,370 points
7,039 views
0 votes
1 answer

How to remove an element from a list in R?

Hi@akhtar, You can remove a value from a ...READ MORE

answered Oct 30, 2020 in Data Analytics by MD
• 95,460 points
4,406 views
0 votes
0 answers

R function rep() in Python (replicates elements of a list/vector)

Each element of a vector is duplicated ...READ MORE

Jun 24, 2022 in Data Analytics by Sohail
• 3,040 points
1,335 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,250 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,921 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by Gitika 1,182 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,342 views
0 votes
1 answer

How do I remove an element from a list by index in R?

Use list[index] = NULL The list value will ...READ MORE

answered Oct 31, 2019 in Data Analytics by Cherukuri
• 33,030 points
2,295 views
0 votes
1 answer

reverse a list or vector in R

@ch, Use rev function to reverse R objects ...READ MORE

answered Oct 14, 2019 in Data Analytics by Cherukuri
• 33,030 points
6,123 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP