Re: [R] extracting character values

2013-01-13 Thread arun
Hi, This should also work: do.call(data.frame,lapply(netw,function(x) gsub("^ *(\\D+) \\w+$","\\1",x))) A.K. From: Biau David To: arun ; r help list Sent: Sunday, January 13, 2013 12:02 PM Subject: Re: [R] extracting character val

Re: [R] extracting character values

2013-01-13 Thread arun
riya #10  riad  biau   res[complete.cases(res),]#removes the NA rows. A.K. From: Biau David To: arun ; r help list Sent: Sunday, January 13, 2013 12:02 PM Subject: Re: [R] extracting character values OK, here is a minimal working example

Re: [R] extracting character values

2013-01-13 Thread arun
HI, Not sure this helps: netw<-read.table(text=" lastname_initial, year Aaron H, 1900 Beecher HW, 1947 Cannon JP, 1985 Stone WC, 1982  van der hoops bf, 1948 NA, 1976 ",sep=",",header=TRUE,stringsAsFactors=FALSE) res1<-sub("^[[:space:]]*(.*?)[[:space:]]*$","\\1",gsub("\\w+$","",netw[,1])) res1[!

Re: [R] extracting character values

2013-01-13 Thread Biau David
 : Re: [R] extracting character values > >Hi, >This should also work: >do.call(data.frame,lapply(netw,function(x) gsub("^ *(\\D+) \\w+$","\\1",x))) >A.K. > > > > > > >From: Biau David >To: arun ; r help list >Se

Re: [R] extracting character values

2013-01-13 Thread Biau David
works great thanks. And you cut off my code a lot and removed the loop.   David Biau > > De : Uwe Ligges >À : Biau David >Cc : arun ; r help list >Envoyé le : Dimanche 13 janvier 2013 18h22 >Objet : Re: [R] extracting character values >

Re: [R] extracting character values

2013-01-13 Thread Uwe Ligges
dim(netw)[2]) { wh <- regexpr('[a-z]{3,}', as.character(netw[,i])) res[i] <- substring(as.character(netw[,i]), wh, wh + attr(wh,'match.length')-1) } There may be an easier solution, but this should do: res <- data.frame(lapply(netw, function(x) gsub

Re: [R] extracting character values

2013-01-13 Thread Uwe Ligges
On 13.01.2013 09:53, Biau David wrote: Dear all, I have a dataframe of names (netw), with each cell including last name and initials of an author; some cells have NA. I would like to extract only the last name from each cell; this new dataframe is calle 'res' Here is what I do: res <- dat

Re: [R] extracting character values

2013-01-13 Thread Biau David
', as.character(netw[,i])) res[i] <- substring(as.character(netw[,i]), wh, wh + attr(wh,'match.length')-1) }  problem is for author "van den hoofs j" who is only retrieved as 'van' thanks, David Biau > > De : a