Re: [R] regroup row names

2016-07-03 Thread Ulrik Stervbo
Do the elements in 'locs' hahabe an _ somewhere? If not the search and
replace find nothing.

Bert's suggestion of taking a substring is better if you are just
interested in characters on fixed positions.

Bert also suggested that you could maybe benefit from reading a few
tutorials and I agree.

Best,
Ulrik

On Sun, 3 Jul 2016, 21:36 lily li,  wrote:

> Hi Ulrik,
>
> I created another column named locs, and used the code df$locs <-
> gsub("_.*", "", df$locs), but I found that the names does not change at
> all. And the new column becomes characters after using the gsub function.
> What is the problem? Thanks again.
>
>
> On Sun, Jul 3, 2016 at 12:41 PM, Ulrik Stervbo 
> wrote:
>
>> Hi Lily,
>>
>> My suggestion should remove the underscore and everything after it,
>> leaving just aClim and bClim in the ID column.
>>
>> Best
>> Ulrik
>>
>> On Sun, 3 Jul 2016, 20:34 lily li,  wrote:
>>
>>> Hi Ulrik,
>>>
>>> Thanks. This is for one group, but how to do for several groups? I tried
>>> gsub(c(),c(),df$ID), but it does not work.
>>>
>>>
>>> On Sun, Jul 3, 2016 at 12:24 PM, Ulrik Stervbo 
>>> wrote:
>>>
 Hi Lily,

 you can use gsub:

 df$ID <- gsub("_.*", "", df$ID)

 HTH
 Ulrik

 On Sun, 3 Jul 2016 at 20:16 lily li  wrote:

> I have a problem in changing row names in a dataframe in R. The first
> column is ID, such as aClim_st02, aClim_st03, aClim_st 05, bClim_st01,
> bClim_st02, etc. How to rename the names, so that aClim_ all grouped to
> aClim, while bClim_ all grouped to bClim? Thanks for your help.
> df
>
> IDtemp   precip   LW   SW
> aClim_st02
> aClim_st03
> aClim_st05
> bClim_st01
> bClim_st02
> ...
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

>>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] regroup row names

2016-07-03 Thread Ulrik Stervbo
Hi Lily,

My suggestion should remove the underscore and everything after it, leaving
just aClim and bClim in the ID column.

Best
Ulrik

On Sun, 3 Jul 2016, 20:34 lily li,  wrote:

> Hi Ulrik,
>
> Thanks. This is for one group, but how to do for several groups? I tried
> gsub(c(),c(),df$ID), but it does not work.
>
>
> On Sun, Jul 3, 2016 at 12:24 PM, Ulrik Stervbo 
> wrote:
>
>> Hi Lily,
>>
>> you can use gsub:
>>
>> df$ID <- gsub("_.*", "", df$ID)
>>
>> HTH
>> Ulrik
>>
>> On Sun, 3 Jul 2016 at 20:16 lily li  wrote:
>>
>>> I have a problem in changing row names in a dataframe in R. The first
>>> column is ID, such as aClim_st02, aClim_st03, aClim_st 05, bClim_st01,
>>> bClim_st02, etc. How to rename the names, so that aClim_ all grouped to
>>> aClim, while bClim_ all grouped to bClim? Thanks for your help.
>>> df
>>>
>>> IDtemp   precip   LW   SW
>>> aClim_st02
>>> aClim_st03
>>> aClim_st05
>>> bClim_st01
>>> bClim_st02
>>> ...
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide
>>> http://www.R-project.org/posting-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] regroup row names

2016-07-03 Thread Bert Gunter
I strongly suspect that you do not need to do this. What I think you
do need to do is to create a new column (which will be a factor)
identifying the climate ("a" or "b"), which can then be used to group
climates in plots, used as a covariate in statistical analyses, etc.
Moreover, there is probably no need for things to be in order (R is
not Excel or SPSS or ...).

You can either use regexp's (e.g. grep -- very powerful but with a
hefty learning curve) or because of the simplicity of your ID's,
?substring ; e.g.

yourdat$clim_type <- substring(yourdat$ID,1,1)

Please do some more tutorials on your own, as these (not regexp's) are
fairly basic R features that all users should be aware of.

Incidentally, check out the "stringr" package, which is supposed to
make string manipulation tasks like this easier (I have not used it
though).

Cheers,
Bert


Bert Gunter

"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Jul 3, 2016 at 11:14 AM, lily li  wrote:
> I have a problem in changing row names in a dataframe in R. The first
> column is ID, such as aClim_st02, aClim_st03, aClim_st 05, bClim_st01,
> bClim_st02, etc. How to rename the names, so that aClim_ all grouped to
> aClim, while bClim_ all grouped to bClim? Thanks for your help.
> df
>
> IDtemp   precip   LW   SW
> aClim_st02
> aClim_st03
> aClim_st05
> bClim_st01
> bClim_st02
> ...
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] regroup row names

2016-07-03 Thread lily li
Hi Ulrik,

Thanks. This is for one group, but how to do for several groups? I tried
gsub(c(),c(),df$ID), but it does not work.


On Sun, Jul 3, 2016 at 12:24 PM, Ulrik Stervbo 
wrote:

> Hi Lily,
>
> you can use gsub:
>
> df$ID <- gsub("_.*", "", df$ID)
>
> HTH
> Ulrik
>
> On Sun, 3 Jul 2016 at 20:16 lily li  wrote:
>
>> I have a problem in changing row names in a dataframe in R. The first
>> column is ID, such as aClim_st02, aClim_st03, aClim_st 05, bClim_st01,
>> bClim_st02, etc. How to rename the names, so that aClim_ all grouped to
>> aClim, while bClim_ all grouped to bClim? Thanks for your help.
>> df
>>
>> IDtemp   precip   LW   SW
>> aClim_st02
>> aClim_st03
>> aClim_st05
>> bClim_st01
>> bClim_st02
>> ...
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] regroup row names

2016-07-03 Thread Ulrik Stervbo
Hi Lily,

you can use gsub:

df$ID <- gsub("_.*", "", df$ID)

HTH
Ulrik

On Sun, 3 Jul 2016 at 20:16 lily li  wrote:

> I have a problem in changing row names in a dataframe in R. The first
> column is ID, such as aClim_st02, aClim_st03, aClim_st 05, bClim_st01,
> bClim_st02, etc. How to rename the names, so that aClim_ all grouped to
> aClim, while bClim_ all grouped to bClim? Thanks for your help.
> df
>
> IDtemp   precip   LW   SW
> aClim_st02
> aClim_st03
> aClim_st05
> bClim_st01
> bClim_st02
> ...
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] regroup row names

2016-07-03 Thread lily li
I have a problem in changing row names in a dataframe in R. The first
column is ID, such as aClim_st02, aClim_st03, aClim_st 05, bClim_st01,
bClim_st02, etc. How to rename the names, so that aClim_ all grouped to
aClim, while bClim_ all grouped to bClim? Thanks for your help.
df

IDtemp   precip   LW   SW
aClim_st02
aClim_st03
aClim_st05
bClim_st01
bClim_st02
...

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.