[R] Help with data management

André Luis Neves andrluis at ualberta.ca
Thu Feb 23 23:37:38 CET 2017


Dear R users,

I have the following dataframes (A, B, and C) stored in a list:

A= data.frame(c("c", "d", "e"),4.4:6.8,c(1,2,3))
colnames(A) <- c ("Family", "NormalizedCount", "Hits")
A


B= data.frame(c("c", "f", "a"),c(3.2,6.4, 4.4), c(1,4,3))
colnames(B) <- c ("Family", "NormalizedCount", "Hits")
B


C= data.frame(c("q", "o", "f"),c(7.2,9.4, 41.4), c(10,4,5))
colnames(C) <- c ("Family", "NormalizedCount", "Hits")
C

mylist <- list(A=A,B=B,C=C)
mylist


My idea is to merge the three dataframes into another dataframe (let's name
it: 'D')  with a structure in which the rows are the Families and columns
the "Hits" of each family detected in the dataframes A, B, and C. If a
given 'Family' does NOT have a 'Hit' in the dataframe we need to assign
number 0 to it.

The dataframe 'D' would need to be populated as follows:


Family                                                      A
       B                                      C
c 1 1 0
d 2 0 0
e 3 0 0
f 0 4 5
a 0 3 0
q 0 0 10
o 0 0 4


Thank you very much for your great help,


​
-- 
Andre

	[[alternative HTML version deleted]]



More information about the R-help mailing list