Greetings all, I have two questions. I have a data set that is arranged in the example below. I wish to obtain a plot of the performance of each ID over Year on v1. It's not clear how I set this up? ID Year V1 1 1980 1 1 1981 2 1 1982 6 1 1983 4 2 1980 5 2 1981 5 2 1982 5 2 1983 6 Also,I would like to transpose the data to have the variable across the columns such as ID v1980 v1981 v1982 v1983 1 1 2 6 4 2 5 5 5 6 Is there a straightforward way to do this in R? Thanks in advance, David -- ======================================================================David Kaplan, Ph.D. Professor Department of Educational Psychology University of Wisconsin - Madison Educational Sciences, Room, 1061 1025 W. Johnson Street Madison, WI 53706 email: dkaplan at education.wisc.edu homepage: http://www.education.wisc.edu/edpsych/default.aspx?content=kaplan.html Phone: 608-262-0836
check out the interaction.plot. This *may* be what you are looking for. ?interaction.plot On Mar 15, 8:14?am, David Kaplan <dkap... at education.wisc.edu> wrote:> Greetings all, > > I have two questions. ?I have a data set that is arranged in the example > below. ?I wish to obtain a plot of the performance of each ID over Year > on v1. ?It's not clear how I set this up? > > ID ?Year ? V1 ? > 1 ? 1980 ? ?1 ? > 1 ? 1981 ? ?2 > 1 ? 1982 ? ?6 > 1 ? 1983 ? ?4 > 2 ? 1980 ? ?5 > 2 ? 1981 ? ?5 > 2 ? 1982 ? ?5 > 2 ? 1983 ? ?6 > > Also,I would like to transpose the data to have the variable across the > columns such as > > ID ? v1980 ? v1981 v1982 v1983 > 1 ? ? ? 1 ? ? ? 2 ? ? ?6 ? 4 > 2 ? ? ? 5 ? ? ? 5 ? ? ?5 ? 6 > > Is there a straightforward way to do this in R? > > Thanks in advance, > > David > > -- > ======================================================================> David Kaplan, Ph.D. > Professor > Department of Educational Psychology > University of Wisconsin - Madison > Educational Sciences, Room, 1061 > 1025 W. Johnson Street > Madison, WI 53706 > > email: dkap... at education.wisc.edu > homepage:http://www.education.wisc.edu/edpsych/default.aspx?content=kaplan.html > Phone: 608-262-0836 > > ______________________________________________ > R-h... at r-project.org mailing listhttps://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guidehttp://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.
On Mar 14, 2009, at 5:14 PM, David Kaplan wrote:> Greetings all, > > I have two questions. I have a data set that is arranged in the > example below. I wish to obtain a plot of the performance of each > ID over Year on v1. It's not clear how I set this up? > ID Year V1 1 1980 1 1 1981 2 1 1982 6 > 1 1983 4 > 2 1980 5 > 2 1981 5 > 2 1982 5 > 2 1983 6?xyplot ?formula> > > Also,I would like to transpose the data to have the variable across > the columns such as > > ID v1980 v1981 v1982 v1983 > 1 1 2 6 4 > 2 5 5 5 6?reshape # or require(reshape) ?cast> > > > Is there a straightforward way to do this in R? > > Thanks in advance, > > David > > -David Winsemius, MD Heritage Laboratories West Hartford, CT
Use reshape in the base of R or melt/cast in the reshape package. Using the former: Lines <- "ID Year V1 1 1980 1 1 1981 2 1 1982 6 1 1983 4 2 1980 5 2 1981 5 2 1982 5 2 1983 6" # DF <- read.table("myfile.dat", header = TRUE) DF <- read.table(textConnection(Lines), header = TRUE) reshape(DF, dir = "wide", idvar = "ID", timevar = "Year") gives for the posted data:> reshape(DF, dir = "wide", idvar = "ID", timevar = "Year")ID V1.1980 V1.1981 V1.1982 V1.1983 1 1 1 2 6 4 5 2 5 5 5 6 On Sat, Mar 14, 2009 at 5:14 PM, David Kaplan <dkaplan at education.wisc.edu> wrote:> Greetings all, > > I have two questions. ?I have a data set that is arranged in the example > below. ?I wish to obtain a plot of the performance of each ID over Year on > v1. ?It's not clear how I set this up? > ID ?Year ? V1 ?1 ? 1980 ? ?1 ?1 ? 1981 ? ?2 1 ? 1982 ? ?6 > 1 ? 1983 ? ?4 > 2 ? 1980 ? ?5 > 2 ? 1981 ? ?5 > 2 ? 1982 ? ?5 > 2 ? 1983 ? ?6 > > Also,I would like to transpose the data to have the variable across the > columns such as > > ID ? v1980 ? v1981 v1982 v1983 > 1 ? ? ? 1 ? ? ? 2 ? ? ?6 ? 4 > 2 ? ? ? 5 ? ? ? 5 ? ? ?5 ? 6 > > > Is there a straightforward way to do this in R? > > Thanks in advance, > > David > > -- > ======================================================================> David Kaplan, Ph.D. > Professor > Department of Educational Psychology > University of Wisconsin - Madison > Educational Sciences, Room, 1061 > 1025 W. Johnson Street > Madison, WI 53706 > > email: dkaplan at education.wisc.edu > homepage: > http://www.education.wisc.edu/edpsych/default.aspx?content=kaplan.html > Phone: 608-262-0836 > > ______________________________________________ > 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. >