rep Questions

4

Solved

I would like to make the following sequence in R, by using rep or any other function. c(1, 2, 3, 4, 5, 2, 3, 4, 5, 3, 4, 5, 4, 5, 5) Basically, c(1:5, 2:5, 3:5, 4:5, 5:5).
Sheridan asked 4/1, 2022 at 13:14

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...
Caudillo asked 28/8, 2013 at 13:2

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(...
Rosemari asked 18/9, 2017 at 13:9

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...
Diaphaneity asked 28/3, 2017 at 8:29

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...
Dimeter asked 17/3, 2017 at 13:13

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

I want to create a list which is eight times the vector c(2,6), i.e. a list of 8 vectors. WRONG: object = as.list(rep(c(2,6),8)) results instead in a list of 16 single numbers: 2 6 2 6 2 6 2 6 .....
Kamerman asked 1/3, 2016 at 23:13

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...
Hartmunn asked 22/5, 2014 at 22:54

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...
Pice asked 8/8, 2012 at 18:10

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...
Shealy asked 9/10, 2012 at 0:46

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...
Yawata asked 6/8, 2012 at 13:42
1

© 2022 - 2024 — McMap. All rights reserved.