Converting a vector of strings into a numerical vector, based on stringsequences
By : phb
Date : March 29 2020, 07:55 AM
like below fixes the issue I have a vector like , Try: code :
A < c("A","A","B","B", "C","C","C", "D")
as.numeric(factor(A))
[1] 1 1 2 2 3 3 3 4
labels(factor(A))
[1] "1" "2" "3" "4" "5" "6" "7" "8"
1:length(A)
[1] 1 2 3 4 5 6 7 8
library(plyr)
mapvalues(A, from=unique(A), to=1:4)
[1] "1" "1" "2" "2" "3" "3" "3" "4"

Parsing a numerical string into a numerical vector with regex
By : TheFroStache
Date : March 29 2020, 07:55 AM
it should still fix some issue I have a set of numerical strings (used in filenames) which I would like to parse into a vectors , Use this code: code :
a = '0_01_1_0_23_0_52_0_25';
a = strrep(a, '0_', '0.');
res = regexp(a, '(?[09]+(?:\.[09]+)?)','match');
res = cellfun(@str2num, res)

Finding elements of a vector based on the numerical positions defined in another vector in R
By : Klaas Z4us V
Date : March 29 2020, 07:55 AM
it should still fix some issue You can use split to split by rep(seq_along(ll), ll) (outputs 1 1 2 3 3 4 4 4). code :
split(long, rep(seq_along(ll), ll))
$`1`
[1] FALSE FALSE
$`2`
[1] FALSE
$`3`
[1] FALSE TRUE
$`4`
[1] TRUE FALSE TRUE

Create dummy equal to one if string vector equal to element in multiple string vector
By : user3146371
Date : March 29 2020, 07:55 AM
it helps some times If I understand the question correctly, the easiest approach is to use an ifelse statement. Please add a reproducible example in your next question to make it easier for those trying to give you solutions. code :
Data < data.frame(a = 0,
b = c("M", "M", "D", "M", "X", "P"),
stringsAsFactors = FALSE)
Data2 < data.frame(a = c("c1", "c2", "c3"),
b = c("M", "X", "P"),
stringsAsFactors = FALSE)
Data$a < ifelse(Data$b %in% Data2$b, 1, 0)

How to merge a character vector conditional on cells of a numerical vector?
By : JustMe
Date : March 29 2020, 07:55 AM
hop of those help? Let's say I have the following character vector A: , You can try:

