about file name

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

about file name

lily li
Hi R users,

I have a string for example 'X35.84375_.100.71875', and I have another
dataframe df that I want to export with the transformed string name
'35.84375_-100.71875' with no extension. How to do this in R? Thanks for
your help.

a = 'X35.84375_.100.71875'
write.table(df, file='', row.names=F, col.names=F)

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: about file name

jholtman
just strip off the first character:

> a
[1] "X35.84375_.100.71875"
> a.new <- sub("^.", '', a)
> a.new
[1] "35.84375_.100.71875"
>


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Thu, Jul 28, 2016 at 3:51 PM, lily li <[hidden email]> wrote:

> Hi R users,
>
> I have a string for example 'X35.84375_.100.71875', and I have another
> dataframe df that I want to export with the transformed string name
> '35.84375_-100.71875' with no extension. How to do this in R? Thanks for
> your help.
>
> a = 'X35.84375_.100.71875'
> write.table(df, file='', row.names=F, col.names=F)
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: about file name

lily li
Thanks, but how to get the string like this:
"35.84375_-100.71875" use the minus sign instead of dot.

On Thu, Jul 28, 2016 at 2:38 PM, jim holtman <[hidden email]> wrote:

> just strip off the first character:
>
> > a
> [1] "X35.84375_.100.71875"
> > a.new <- sub("^.", '', a)
> > a.new
> [1] "35.84375_.100.71875"
> >
>
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
> On Thu, Jul 28, 2016 at 3:51 PM, lily li <[hidden email]> wrote:
>
>> Hi R users,
>>
>> I have a string for example 'X35.84375_.100.71875', and I have another
>> dataframe df that I want to export with the transformed string name
>> '35.84375_-100.71875' with no extension. How to do this in R? Thanks for
>> your help.
>>
>> a = 'X35.84375_.100.71875'
>> write.table(df, file='', row.names=F, col.names=F)
>>
>>         [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: about file name

jholtman
add another step: (need to learn about regular expressions)

> a
[1] "X35.84375_.100.71875"
> a.new <- sub("^.", '', a)
> a.new
[1] "35.84375_.100.71875"
> sub("_.", "_-", a.new)
[1] "35.84375_-100.71875"
>


Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.

On Thu, Jul 28, 2016 at 4:39 PM, lily li <[hidden email]> wrote:

> Thanks, but how to get the string like this:
> "35.84375_-100.71875" use the minus sign instead of dot.
>
> On Thu, Jul 28, 2016 at 2:38 PM, jim holtman <[hidden email]> wrote:
>
>> just strip off the first character:
>>
>> > a
>> [1] "X35.84375_.100.71875"
>> > a.new <- sub("^.", '', a)
>> > a.new
>> [1] "35.84375_.100.71875"
>> >
>>
>>
>> Jim Holtman
>> Data Munger Guru
>>
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
>>
>> On Thu, Jul 28, 2016 at 3:51 PM, lily li <[hidden email]> wrote:
>>
>>> Hi R users,
>>>
>>> I have a string for example 'X35.84375_.100.71875', and I have another
>>> dataframe df that I want to export with the transformed string name
>>> '35.84375_-100.71875' with no extension. How to do this in R? Thanks for
>>> your help.
>>>
>>> a = 'X35.84375_.100.71875'
>>> write.table(df, file='', row.names=F, col.names=F)
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] 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]]

______________________________________________
[hidden email] 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.
Reply | Threaded
Open this post in threaded view
|

Re: about file name

Rui Barradas
In reply to this post by lily li
Hello,

Just use ?sub.

x <- "35.84375_.100.71875"
y <- sub("_\\.", "_-", x)

Hope this helps,

Rui Barradas
 

Citando lily li <[hidden email]>:

> Thanks, but how to get the string like this:
> "35.84375_-100.71875" use the minus sign instead of dot.
>
> On Thu, Jul 28, 2016 at 2:38 PM, jim holtman <[hidden email]> wrote:
>> just strip off the first character:
>>
>> a
>> [1] "X35.84375_.100.71875"
>> a.new <- sub("^.", '', a)
>> a.new
>> [1] "35.84375_.100.71875"
>>
>> Jim Holtman
>> Data Munger Guru
>>
>> What is the problem that you are trying to solve?
>> Tell me what you want to do, not how you want to do it.
>>
>> On Thu, Jul 28, 2016 at 3:51 PM, lily li <[hidden email]> wrote:
>>> Hi R users,
>>>
>>> I have a string for example 'X35.84375_.100.71875', and I have another
>>> dataframe df that I want to export with the transformed string name
>>> '35.84375_-100.71875' with no extension. How to do this in R? Thanks for
>>> your help.
>>>
>>> a = 'X35.84375_.100.71875'
>>> write.table(df, file='', row.names=F, col.names=F)
>>>
>>>         [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> [hidden email] 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]]
>
> ______________________________________________
> [hidden email] 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.htmland provide commented,  
> minimal, self-contained, reproducible code.

 

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] 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.