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
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
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
>
>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
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
>
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
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
', 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
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=
9 matches
Mail list logo