Re: [R] make dataframe from table

From: John Kane <jrkrideau_at_yahoo.ca>
Date: Mon, 4 Feb 2008 12:06:24 -0500 (EST)


You need to create a data.frame in a different way is all

Try this:

df1 <-
data.frame(rownames(affect),matrix(affect,nrow=3)) merge(age,df1, by.x=1, by.y=1)

> Dear R-experts,
>
>
> I have got a dataframe:
> data
> ID disease
> V1 V2
> 1 p1 1
> 2 p1 3
> 3 p3 3
> 4 p3 5
> 5 p5 1
>
> >From which I extract a usefull table: affect
>
> affect
> 1 3 5
> p1 1 1 0
> p3 0 1 1
> p5 1 0 0
>
> I want to merge this with anotherdataframe:
> age
> p1 23
> p2 24
> p3 23
> p4 11
> p5 45
>
> If have tried as.data.frame(affect) and other
> solutions to get the
> following comment going:
> merge(age,affect, by.x=0, by.y=1)
>
> QUESTION: I can get the merging process going with
> the outcome of the
> table command.
>
> Any help would be great.
>
> R for windows v2.6.1
>
> code:
>
>
data<-as.data.frame(matrix(c("p1","p1","p3","p3","p5",1,3,3,5,1),5,2))
>

age<-as.data.frame(matrix(c("p1","p2","p3","p4","p5",23,24,23,11,45),5,2
> ))
> affect<-table(data[,1],data[,2])
> merge(age,affect, by.x=0, by.y=1)
>
>
> BW
>
> Marco
>
>
> [[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.
>

      Looking for the perfect gift? Give the gift of Flickr!



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. Received on Mon 04 Feb 2008 - 17:08:56 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Mon 04 Feb 2008 - 18:30:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive