rep Questions
4
Solved
6
Solved
I am trying to replicate a dataframe (zoo object) 50 times as a whole, and get the result as a matrix, but all the commands I have tried seems to be unsuccessful. I could easily write a function th...
3
Solved
Begin a new R session with an empty environment. Write a series of functions with a parameter that is to be used as the value of the times parameter in a call to rep().
f <- function(n) {
rep(...
4
Solved
I am trying to generate a vector containing decreasing sequences of increasing length, such as 1, 2,1, 3,2,1, 4,3,2,1, 5,4,3,2,1, i.e.
c(1, 2:1, 3:1, 4:1, 5:1)
I tried to use a loop for this, but I...
4
Solved
I would like to create a sequence from two numbers, such that the occurrence of one of the numbers decreases (from n_1 to 1) while for the other number the occurrences are fixed at n_2.
I've been...
4
Solved
I am trying to calculate a median value across a number of columns, however my data is a bit funky. It looks like the following example.
library(data.table)
dt <- data.table("ID" = c(1,2,3,4),...
Hardboard asked 1/6, 2016 at 21:48
1
Solved
1
Solved
How to assign more than one value for "each" argument in "rep" function in R?
A trivial example, where each value in a vector is 3-times repeated in a row:
a <- seq(2,6,2)
rep (a,each = 3)
H...
2
Solved
When I perform:
rep(1:4, rep(4,4))
I get
1 1 1 1 2 2 2 2 3 3 3 3 4 4 4 4
which is expected. But then when I try to fix the length to 16(which is the length of the output) as follows:
rep(1...
1
x=1:20
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
rep(x,2)
[1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
View(r...
2
Solved
I have a data frame with 1666 rows. I would like to add a column with a repeating sequence of 1:5 to use with cut() to do cross validation. It would look like this:
Y x1 x2 Id1
1 .15 3.6 1
0 1.1...
1
© 2022 - 2024 — McMap. All rights reserved.