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
quot;\\1",gsub("\\w+$","",netw[,1])) res1[!is.na(res1)] #[1] "Aaron" "Beecher"   "Cannon"    "Stone"    #[5] "van der hoops" A.K. ----- Original Message ----- From: Biau David To: r help list Cc: Sen

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

[R] extracting character values

2013-01-13 Thread Biau David
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 <- data.frame(matrix(NA, nrow=dim(netw)[1], ncol=