[R] check for data in a data.frame and return correspondent number

mari681 marianna.bolognesi at gmail.com
Wed Mar 14 18:49:13 CET 2012


Dear R-ers,

still the newbie. With a question about coordinates of a vector appearing or
not in a data.frame.
I have a data.frame (MyData) with 3 columns which looks like this:

                       V1        V4              redNew
                     red-j   10.5032      appearance blood-n
                     red-j    9.3749       appearance ground-n
                     red-j   10.2167      appearance sea-n
                     red-j   10.8200      appearance sky-n
                    red-j    9.2831       area chicken-n
                    red-j    8.2838        area color-n

and a MyVector  which includes also (but not only) the data in the 3rd
column:

                         " appearance blood-n"
                        "  appearance ground-n"
                          "appearance sea-n"
                          "as_adj_as fire-n"
                         "as_adj_as carrot-n"
                         "appearance sky-n"
                       " area chicken-n"
                        "area color-n"

I would like to get a data.frame of 2 columns where in the first column
there is all MyVector, and in the second column  there is either the
correspondent number found in MyData (shown in column 2) or a "0" if the
entrance is not found.

I've tried some options, among which a loop:

out<-for(x in MyVector) if (x %in% MyData) print (MyData[,2])

but obviously doesn't work.
How can I select the correspondent element on column 2 for each x found in
column 3?

Suggestions in general?
Thank you for consideration!!!
                         
Have a nice day,
Marianna


--
View this message in context: http://r.789695.n4.nabble.com/check-for-data-in-a-data-frame-and-return-correspondent-number-tp4472634p4472634.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list