Sto cercando di estrarre i caratteri prima e dopo il carattere "/" usando R.caratteri estrarre fino a "/" utilizzando R
Per esempio, posso ottenere i tag con il seguente:
s <- "hello/JJ world/NN"
# get the tags
sapply(s, function(x){gsub("([a-z].*?)/([A-z].*?)", "\\2", x)})
che restituisce
"JJ NN"
Tuttavia, quando si tenta di estrarre i caratteri prima del "/" o il "token", utilizzando il seguente:
sapply(s, function(x){gsub("([a-z].*?)/([A-z].*?)", "\\1", x)})
ottengo
"helloJ worldN"
Come posso ottenere "ciao mondo" e perché è la prima lettera del tag scivolare dentro?
stai usando saply su un vettore di lunghezza uno. perché non solo 'gsub ('/ [az] +', '', s, ignore.case = TRUE)' e 'gsub ('[az] + /', '', s, ignore.case = TRUE)' ? – rawr
Prova 'gsub ('/ \\ w +', '', s)' – akrun