Skip to content

extracting character values

6 messages · Biau David, arun, Uwe Ligges

#
Hi,
If you want the NA rows removed, you could, otherwise:
?res<-do.call(data.frame,lapply(netw,function(x) sub("^[[:space:]]*(.*?)[[:space:]]*$","\\1",gsub("\\w+$","",x))))
?res
#???????????? au1?????? au2?????? au3
#1?????????? biau???? weiss?? bhumbra
#2????????? jones? ferguson?????? lam
#3? van den hoofs greidanus??? garbuz
#4?????????? biau?? porcher????? <NA>
#5?????????? biau? ferguson???? chung
#6?????? campagna??? pessis????? biau
#7?????????? biau?? leclerc??? marmor
#8????????? weiss????? biau?? bhumbra
#9????? verdegaal???? bovee pansuriya
#10????????? riad????? biau????? <NA>
?res[complete.cases(res),]#removes the NA rows.
A.K.
#
On 13.01.2013 18:02, Biau David wrote:
There may be an easier solution, but this should do:

res <- data.frame(lapply(netw,
      function(x)
        gsub("^ *([[:alpha:] ]*) +[[:alpha:]]+$", "\\1", x)))

Uwe Ligges
#
Hi,
This should also work:
do.call(data.frame,lapply(netw,function(x) gsub("^ *(\\D+) \\w+$","\\1",x)))
A.K.