R: Vector Group by Defined group [closed] - r

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I have a vector c("A","B","C",......) and a list list(c("A"),c("B","C"))
I want to get a vector c(1,2,2....)
Is there any function in some basic packages?

we can use merge
merge(stack(setNames(lst, seq_along(lst))), data.frame(values=v1))$ind

Related

generate all possible k-mers from a vector and also remaining in r [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
Suppose we have a vector [1:10] of players, I want to generate all possible roommates for these playes (not combn(10, 2))
Can you help me?
Thank you
You can iterate over combn(with different ks)
x= 1:10
lapply(1:length(x), function(k) combn(x,k))

How to interpret the following operations in R programming language? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
Here is what to be coded in R:
sum_{n=1}^{10}\left(\frac{2^{n}}{n^2} + \frac{n^{4}}{4^{n}}\right)
With purrr I'd say something like:
sum(map_dbl(1:10, fun(x) 2^x/^2+x^4/4^x)

Rstudio rep() and seq() [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
Improve this question
I need to iterate a sequence that is being repeated.
Say I have a vector of 1,2,3 I want printed out 5 times.
each time needs to be inceased by one.
so 1,2,3,2,3,4,3,4,5,4,5,6,5,6,7
rep(1:3, 5) + rep(0:4, each=3)
should do the trick

R: Barplot, add value directly next to bar and a description in a separate column [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
How can I achieve somethign like this in R:
like this?
vec <- runif(5)
plot(0,0,type="n",xlim=c(0,1.5),ylim=c(0,7),bty="n",axes="off")
at<-barplot(vec,horiz=TRUE,add=TRUE)
text(vec,at,signif(vec,1),pos=4)
text(rep(1,5),at,c("mn","lu","co","-","my"))

data.table complex manipulation with rows elimination [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
Data sample is below: I have 3million rows.
Date,id,type,qty
9/30/14,1,’A’,10
9/30/14,2,’Z’,12
9/30/14,3,’B’,15
9/30/14,1,’B’,20
9/30/14,1,’Z’,20
9/30/14,1,’A’,20
9/30/14,2,’B’,20
9/30/14,3,’B’,5
9/30/14,3,’A’,40
I want result as below:
Date,id,type,Qty
9/30/14,1,A,20
9/30/14,1,B,20
9/30/14,2,B,20
9/30/14,3,B,5
9/30/14,3,’A’,40
Logic is below: On the same date, pick the latest qty (from the later record) for each id and type.Ignore types y and Z.
DT[,.(Qty=last(qty)),by=.(Date,id,type)][type!='Z'][order(id)]

Resources