Tag: r
-
Check monotonically increasing per row
10 I have a dataframe as the following : COL_1 COL_2 COL_3 COL_4 COL_5 COL_6 <int> <int> <int> <int> <int> <int> 1 1 1 1 1 1 1 2 1 1 1 1 1 2 3 1 1 1 1 1 3 4 1 1 1 1 1 4 5 1 2 1 1 1…
-
Find the first of the last 1’s sequence
13 I have the following vectors with 0s and 1s: test1 <- c(rep(0,20),rep(1,5),rep(0,10),rep(1,15)) test1 [1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1…
-
Efficiently match all values of a vector in another vector
11 I’m looking to find an efficient method of matching all values of vector x in vector y rather than just the first position, as is returned by match(). What I’m after essentially is the default behavior of pmatch() but without partial matching: x <- c(3L, 1L, 2L, 3L, 3L, 2L) y <- c(3L, 3L,…
-
I want to match similar words between columns
7 1.0 2.0 3.0 loud complaint problems pain stress confused dull pain stress this is my data set and I would like to reorganize the rows so that if there is a word that appears in each column it is transferred to a corresponding row. For example 1.0 2.0 3.0 loud NA NA pain pain…
-
How to replace characters in a string one at a time generating new string for each replacement?
6 I have a vector of strings c("YSAHEEHHYDK", "HEHISSDYAGK", "TFAHTESHISK", "ISLGEHEGGGK", "LSSGYDGTSYK", "FGTGTYAGGEK", "VGASTGYSGLK", "TASGVGGFSTK", "SYASDFGSSAK", "LYSYYSSTESK") for each string I would like to replace "Y", "S" or "T" with "pY", "pS" or "pT". But I dont want all the replacements to be in the same final string, I want each replacement to generate a…