Slicing a list using an index vector in r

0 votes
How to slice a list using an index vector in R?
Oct 9 in Data Analytics by anonymous
• 3,290 points
42 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 by Cherukuri
• 32,260 points

Related Questions In Data Analytics

0 votes
1 answer

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

Yes, we can find the index of ...READ MORE

answered Apr 13, 2018 in Data Analytics by zombie
• 3,710 points
1,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 darklord
• 6,190 points
219 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 in Data Analytics by anonymous
3,890 views
0 votes
1 answer

How to convert a list to data frame in R?

Let's assume your list of lists is ...READ MORE

answered Apr 12, 2018 in Data Analytics by nirvana
• 3,060 points

edited Apr 12, 2018 by nirvana 4,101 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
128 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
184 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
91 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
115 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 in Data Analytics by Cherukuri
• 32,260 points
40 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 in Data Analytics by Cherukuri
• 32,260 points
25 views