[R] Changing content of column in data.frame + efficient join extraction between 2 data.frames

Bernardo Rangel Tura tura at centroin.com.br
Tue Mar 23 11:29:31 CET 2010


On Tue, 2010-03-23 at 09:37 +0000, Corrado wrote:
> Dear R users,
> 
> I have 2 SpatialPointsDataFrame's, pcs and East.
> 
> The column str_1 in the first (pcs) is:
> 
>  > pcs[0:4,]
>        coordinates cat   str_1  int_1  int_2    dbl_1     dbl_2
> 1 (101000, 263000)   1 "SM06B" 101000 263000 4.978915 -4.293668
> 2 (101000, 265000)   2 "SM06C" 101000 265000 4.960478 -4.266742
> 3 (101000, 267000)   3 "SM06D" 101000 267000 4.912984 -4.246849
> 4 (101000, 269000)   4 "SM06E" 101000 269000 4.613309 -4.185405
>  >
> 
> The column str_1 in the second (East) is:
> 
>  > East[0:4,]
>        coordinates str_1
> 1 (489000, 215000) sp81x
> 2 (489000, 217000) sp81y
> 3 (493000, 209000) sp90j
> 4 (495000, 209000) sp90p
>  >
> 
> I would like to do 2 things:
> 
> 1) I would like to change the format of the column str_1
> in the first to be the same that it is in the second,
> that is I need to remove the inverted commas " and I need to
> make it lower case.
> 
> 2) I would like to extract the rows from the first one (pcs) where 
> pcs$str_1
> is the same as East$str_1.
> 
> I have even tried regexp, but cannot modify
> the content of pcs$str_1 to remove
> the inveretd commas " and change the case to lowercase.
> 
> How do I do that?
> 
> Regards


Hi Corrado!

First: tolower(pcs$str_1) change to lower case
Second: try merge (East,pcs,by.x=str_1,by.y=str_1) to fusion data frames
Third: I don't recreate your database East in my computer do you give a
small part to I try solve your problem?

-- 
Bernardo Rangel Tura, M.D,MPH,Ph.D
National Institute of Cardiology
Brazil



More information about the R-help mailing list