[R-sig-Geo] help to change charactwer name in a row of data.frame

Paul Hiemstra paul.hiemstra at knmi.nl
Thu Sep 22 09:04:59 CEST 2011


 On 09/21/2011 03:05 PM, Ndjido Ardo BAR wrote:
> Dear Gianni,
>
> you can also convert your x-column to be a character and then assign any
> value to the line you will, just as follows
>
> df <- data.frame(x=c("a","b","c"),y=c(1,2,3))
>
> df$x<-as.character(df$x)
>
> df[which(df$x=="b"),'x']<-"b%"       # notice the whith() statement can be
> replace by any number of line, as you may know

The which statement is superfluous, the vector (df$x == "b") is sufficient.

cheers,
Paul

>  df
>    x y
> 1  a 1
> 2 b% 2
> 3  c 3
>
>
> Cheers,
> Ardo.
>
>
> On Wed, Sep 21, 2011 at 4:18 PM, gianni lavaredo
> <gianni.lavaredo at gmail.com>wrote:
>
>> Dear Reaserchers,
>>
>> sorry for desturb you, but i tryed several solution but without results. I
>> have a data.frame (it's an example to explain)
>>
>> df <- data.frame(x=c("a","b","c"),y=c(1,2,3))
>>
>>> df
>>  x y
>> 1 a 1
>> 2 b 2
>> 3 c 3
>>
>>
>> and i wish to change same paramters in the column "x" as the following
>> result
>>
>>> df
>>  x y
>> 1 a 1
>> 2 b% 2
>> 3 c 3
>>
>>
>> thanks in advance. Normally to result easy stuff we spent a afternoon when
>> you need to send the result in the night
>>
>> Gianni
>>
>>        [[alternative HTML version deleted]]
>>
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo at r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
> 	[[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo


-- 
Paul Hiemstra, Ph.D.
Global Climate Division
Royal Netherlands Meteorological Institute (KNMI)
Wilhelminalaan 10 | 3732 GK | De Bilt | Kamer B 3.39
P.O. Box 201 | 3730 AE | De Bilt
tel: +31 30 2206 494

http://intamap.geo.uu.nl/~paul
http://nl.linkedin.com/pub/paul-hiemstra/20/30b/770



More information about the R-sig-Geo mailing list