Skip to content

How to merge a matrix and a dataframe with different types of columns

2 messages · Marco, PIKAL Petr

1 day later
#
Hi
columns
Hm. You are not telling the whole story

 typeof(seq(as.Date(Sys.time())-100, as.Date(Sys.time()),10) )
[1] "double"

 str(seq(as.Date(Sys.time())-100, as.Date(Sys.time()),10) )
 Date[1:11], format: "2011-04-16" "2011-04-26" "2011-05-06" "2011-05-16" 
...
Anyway, you can change it to date by as.Date function.
double
<snip>
Why as.matrix? this transforms it to matrix which needs to have the same 
type of data so R tries it best to transform everithing to suit this 
condition.

what do you mean by=1

By my opinion you need

Convert both sets to data frame and for further operation to name the 
columns you want to merge by with the same name.

Transform values in both common columns to the same type of data, in your 
case most probably by as.Date

do
mergedM <- merge(df1, df2, all=T)

Regards
Petr

BTW I needed to look at merge help page and the same should do you.
don't
data
http://www.R-project.org/posting-guide.html