Hello all and thanks in advance for any help or direction. I have co-authorship data that looks like: Paper Author Year 1 SmithKK JonesSD 2008 2 WallaceAR DarwinCA 1999 3 HawkingS 2003 I would like: Paper Author Year 1 SmithKK 2008 1 JonesSD 2008 2 WallaceAR 1999 2 DarwinCA 1999 3 HawkingS 2003 Thanks for your patience with what is likely an easy question <r-help@r-project.org> [[alternative HTML version deleted]]
Hi, name of the data.frame is assumed to be dt. cnt.tmp <- strsplit(dt$Author, " ") cnt <- sapply(cnt.tmp, length) paper.cnt <- dt$Paper[cnt] author <- unlist(cnt.tmp) year <- dt$Year[cnt] dt.new <- data.frame(Paper = paper.cnt, Author = author, Year = year) HTH, Dong-hyun Oh On Aug 27, 2008, at 9:27 PM, Grant Gillis wrote:> Hello all and thanks in advance for any help or direction. I have > co-authorship data that looks like: > > > Paper Author Year > 1 SmithKK JonesSD 2008 > 2 WallaceAR DarwinCA 1999 > 3 HawkingS 2003 > > > I would like: > Paper Author Year > 1 SmithKK 2008 > 1 JonesSD 2008 > 2 WallaceAR 1999 > 2 DarwinCA 1999 > 3 HawkingS 2003 > > > > Thanks for your patience with what is likely an easy question > <r-help at r-project.org> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
Jorge Ivan Velez
2008-Aug-27 19:59 UTC
[R] problems formating scientific collaboration data
Dear Grant, Try this: x="Paper, Author, Year 1,SmithKK JonesSD, 2008 2,WallaceAR DarwinCA, 1999 3,HawkingS, 2003" X=read.delim2(textConnection(x),sep=",",header=TRUE) closeAllConnections() author= strsplit(as.character(X$Author)," ") l=lapply(author,length) P=rep(X$Paper,l) Y=P=rep(X$Year,l) X.new=data.frame(Paper=P,Authore=unlist(author),Year=Y) X.new HTH, Jorge On Wed, Aug 27, 2008 at 3:27 PM, Grant Gillis <grant.j.gillis@gmail.com>wrote:> Hello all and thanks in advance for any help or direction. I have > co-authorship data that looks like: > > > Paper Author Year > 1 SmithKK JonesSD 2008 > 2 WallaceAR DarwinCA 1999 > 3 HawkingS 2003 > > > I would like: > Paper Author Year > 1 SmithKK 2008 > 1 JonesSD 2008 > 2 WallaceAR 1999 > 2 DarwinCA 1999 > 3 HawkingS 2003 > > > > Thanks for your patience with what is likely an easy question > <r-help@r-project.org> > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >[[alternative HTML version deleted]]