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
3,183 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
• 32,930 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 11, 2020 in Data Analytics by Rajiv
• 8,880 points
40,278 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 13, 2018 in Data Analytics by Sahiti
• 6,380 points
2,380 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,160 points
1,757 views
0 votes
2 answers

How to use group by for multiple columns in dplyr, using string vector input in R?

data = data.frame(   zzz11def = sample(LETTERS[1:3], 100, replace=TRUE),   zbc123qws1 ...READ MORE

answered Aug 5, 2019 in Data Analytics by anonymous
9,931 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
1,252 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
653 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 260 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
425 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
• 32,930 points
818 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
• 32,930 points
1,736 views