Questions tagged [rep]

rep is a base package function in R to replicate the elements of a vector

rep is a base function in the R programming language . It takes a vector or other data structure and replicates its elements the specified number of times.

179 questions
0
votes
1 answer

using rep() in a for loop

How can I repeat the integers 1:20 in a vector 20 times each? i want something like s <- 1,1,1,2,2,2,3,3,3 etc..... (except 20 1's then 20 2's then 20 3's.... you get the idea) I am trying this l <- 1:20 S <- for(i in l) rep(i, 20) an one liner…
c0ba1t
  • 241
  • 2
  • 15
0
votes
2 answers

Duplication of elements from a data frame

I have a data frame that looks like this: x <- as.data.frame(matrix(data = c("a", "b", "c", 1, 2, 3), ncol = 2, nrow = 3, byrow = FALSE)) > x V1 V2 1 a 1 2 b 2 3 c 3 Lets say…
max.mustermann
  • 127
  • 1
  • 1
  • 9
-1
votes
1 answer

how to create a vector of different repeated strings in R

I have a vector called samples which is the following: my_samples = c("16S-P030N" ,"16S-P034N", "16S-P035N") I need to create a vector of each value repeated 30 times so what I usually do is the following: rep_samples_vector =…
Valentin
  • 399
  • 2
  • 10
-1
votes
1 answer

Special sequence in R

I would like to create the follow sequence without a loop for a value d greater equal 1: c(d:2, d:3, d:4, ..., d:(d-1), d) Is this possible? Thank you in advance!
anjo1659
  • 41
  • 5
-1
votes
3 answers

Create a vector of ascending numbers based on the value of another vector

I have a data frame named my_df with the following information: Id_user Id_log Condition 123 a day 124 a day 125 a night 126 b day 127 b day 130 c night I would like to make a new column with…
-1
votes
1 answer

rep() and filter() in python calculation running mean

For some statistical whatnot I decided to calculate the running mean with the rep() function in r. However, I'd like to transfer this to python because my r library is limited. I did find that np.repeat is supposed to be similar to rep(), however, I…
scriptgirl_3000
  • 161
  • 3
  • 16
-1
votes
1 answer

Adding Zero to a column in first x rows in R

I am creating a classification model for forecasting purposes. I have several ext files which I converted into one large list containing several lists (called comb). I then broke the large list into a separate dataframe with each list as its own…
sfyn
  • 35
  • 2
  • 8
-1
votes
3 answers

Create this vector using rep() and seq()

I'm starting with R language and I have to create this vector using rep() and seq(). 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 5 6 7 8 9 I've been trying some stuff but but I'm not achieving it.
Hotkrat
  • 9
  • 1
  • 3
-2
votes
2 answers

Make a column based a repetitive numbers that follows another column

I have this data and I want to make a new column: structure(list(AGE_GROUP = c("21-30", "31-40", "41-50"), DATE = c("12/17/2020", "12/17/2020", "12/17/2020"), VACCINE_COUNT = c(36L, 47L, 26L), PERC_TOTAL_VACC = c(24.82758621, 32.4137931,…
Ali Roghani
  • 495
  • 2
  • 7
-2
votes
2 answers

How to repeat sequence of days 1:7 based on continuous days to correspond with weeks

I want to add a column of days each week to my dataset which contains continuous days and continuous weeks already for a large dataset I've tried to use the floor function and the rep function already Edit I'm attempting to automate the final output…
Sparky
  • 349
  • 1
  • 12
-2
votes
2 answers

Creating repeating set from another column in R

Using these dataset: [A] 100 200 300 [B] A B C I would like to make this column: [A] [B] 100 A 100 B 100 C 200 A 200 B 200 C 300 A 300 B 300 C I would like to use rep function in R, but it does not work. How do I…
jhyeon
  • 456
  • 4
  • 14
-2
votes
2 answers

Creating a repeating sequence in R

I need to create a pattern like this with the rep() and seq() commands. It should look like this: [1] 0.0 0.0 0.0 0.8 0.8 0.8 1.6 1.6 1.6 2.4 2.4 2.4 3.2 3.2 3.2 4.0 4.0 4.0 4.8 [20] 4.8 4.8 Do you have any idea how to do so?
Domewitz
  • 21
  • 2
-2
votes
1 answer

A Simple R Loop

I was wondering how to make a simple "loop" to create 21 vertical lines in my plot using "segments()" command? Specifically, I want the 21 vertical lines to be equally spaced going from 21 consecutive points on the X axis all to 1 on the Y axis. So,…
-2
votes
3 answers

How to create an increasing matrix?

Well, I have searched a lot of questions but nothing works. Here is my question, I was asked to create a matrix like this # [,1] [,2] [,3] [,4] [,5] # [1,] 1 2 3 4 5 # [2,] 2 3 4 5 6 # [3,] 3 4 5 6 …
Liu Oreo
  • 29
  • 2
1 2 3
11
12