Placing brackets around the values in a data frame

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

Placing brackets around the values in a data frame

Abraham Mathew-2
Lets say I have the following data frame.

df = data.frame(word = c("David", "James", "Sara", "Jamie", "Jon"))
df

I was trying to place brackets , [ ] , around each string.

I'll be exporting it with write.table and quotes=FALSE, so it will
eventually look like:

[David]
[James]
[Sara]
....


Can anyone help with this task?

I'd like to avoid regular expressions, but I haven't been able to use the
paste function
to get the desired result.

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
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: Placing brackets around the values in a data frame

Uwe Ligges-3


On 27.07.2011 20:00, Abraham Mathew wrote:
> Lets say I have the following data frame.
>
> df = data.frame(word = c("David", "James", "Sara", "Jamie", "Jon"))
> df
>
> I was trying to place brackets , [ ] , around each string.
>
> I'll be exporting it with write.table and quotes=FALSE, so it will
> eventually look like:

Homework? Ask your supervisor!

Uwe Ligges



> [David]
> [James]
> [Sara]
> ....
>
>
> Can anyone help with this task?
>
> I'd like to avoid regular expressions, but I haven't been able to use the
> paste function
> to get the desired result.
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> 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.

______________________________________________
[hidden email] mailing list
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: Placing brackets around the values in a data frame

David Winsemius
In reply to this post by Abraham Mathew-2

On Jul 27, 2011, at 2:00 PM, Abraham Mathew wrote:

> Lets say I have the following data frame.
>
> df = data.frame(word = c("David", "James", "Sara", "Jamie", "Jon"))
> df
>
> I was trying to place brackets , [ ] , around each string.
>
> I'll be exporting it with write.table and quotes=FALSE, so it will
> eventually look like:
>
> [David]
> [James]
> [Sara]
> ....
>
>
> Can anyone help with this task?

?paste


>
> I'd like to avoid regular expressions, but I haven't been able to  
> use the
> paste function
> to get the desired result.

Hmm. Why not?

df$word <- paste("[", df$word, "]", sep="")  # seems to work fine.

>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> [hidden email] mailing list
> 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.

David Winsemius, MD
West Hartford, CT

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