[R] problem with recording numeric output into another dataframe

Rnewbie xuancj at yahoo.com
Thu Aug 6 18:41:48 CEST 2009


dear all,

I have two dataframes

dataframe1
ID
a
b
c

dataframe2
ID       value
a;W      100
X;c      200
Y;Z      300

I wanted to match the IDs from the two dataframes and record the values into
a new column of dataframe1 at the corresponding rows. This is what I expect:

dataframe1
ID     value
a      100
b      
c      200

I tried doing it like this:

for (i in seq(1:nrow(dataframe1))) {
           dataframe1[i,"value"]<-dataframe2[grep(dataframe1[i,"ID"],
dataframe2$ID),"value"]
}

but I failed. I was able to extracted the values from dataframe2 but not
able to record the values in the corresponding rows of dataframe1.

I would appreciate any suggestions. Thanks in advance.

Jim
-- 
View this message in context: http://www.nabble.com/problem-with-recording-numeric-output-into-another-dataframe-tp24850155p24850155.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list