> On Thursday 03 April 2003 01:54, John Miyamoto wrote:
> > The following function combines the character vector into a string
> > in the way that I want, but it seems somewhat inelegant.
> >
> > paste.vector <- function(x, ...) {
> > output <- NULL
> > for (i in 1:length(x)) output <- p
Yes there is.
> x <- c("Bob", "loves", "Sally")
> paste(x, collapse=" ")
[1] "Bob loves Sally"
-Original Message-
From: John Miyamoto [mailto:[EMAIL PROTECTED]
Sent: Thursday, April 03, 2003 7:54 AM
To: R discussion group
Subject: [R] Combining the components of a character vector
De
>Suppose I have a character vector.
>
> x <- c("Bob", "loves", "Sally")
>
> I want to combine it into a single string: "Bob loves Sally" .
> paste(x) yields:
> paste(x)
> [1] "Bob" "loves" "Sally"
>
> Is there a more natural (no loop) way to do this in R?
>
RTFM:
> paste(x, collapse=" ")
Try the "collapse" argument in paste(), i.e.
paste(x,collapse=" ")
John Miyamoto wrote:
Dear Help,
Suppose I have a character vector.
x <- c("Bob", "loves", "Sally")
I want to combine it into a single string: "Bob loves Sally" .
paste(x) yields:
paste(x)
[1] "Bob" "loves" "Sally"
The foll
Please, have a closer look at the help file for paste(), and use the
"collapse" arguments.
Jerome
On April 2, 2003 03:54 pm, John Miyamoto wrote:
> Dear Help,
>Suppose I have a character vector.
>
> x <- c("Bob", "loves", "Sally")
>
> I want to combine it into a single string: "Bob loves S
From ?paste:
If a value is specified for `collapse', the values in the result
are then concatenated into a single string, with the elements
being separated by the value of `collapse'.
> paste(c("Bob", "loves", "Sally"), collapse=" ")
[1] "Bob loves Sally"
>
At Wednesday 03:54 PM 4/2/
paste( c("Bob", "loves", "Sally"), collapse=" ")
Spencer Graves
John Miyamoto wrote:
Dear Help,
Suppose I have a character vector.
x <- c("Bob", "loves", "Sally")
I want to combine it into a single string: "Bob loves Sally" .
paste(x) yields:
paste(x)
[1] "Bob" "loves" "Sally"
The followin
At 15:54 -0800 2.4.2003, John Miyamoto wrote:
>Dear Help,
> Suppose I have a character vector.
>
>x <- c("Bob", "loves", "Sally")
>
>I want to combine it into a single string: "Bob loves Sally" .
>[...]
>Is there a more natural (no loop) way to do this in R?
>
>John Miyamoto
paste(x, sep = "",
Dear John,
Try paste(x, collapse=" ")
John
At 03:54 PM 4/2/2003 -0800, John Miyamoto wrote:
Dear Help,
Suppose I have a character vector.
x <- c("Bob", "loves", "Sally")
I want to combine it into a single string: "Bob loves Sally" .
paste(x) yields:
paste(x)
[1] "Bob" "loves" "Sally"
The
Use the collapse argument to paste.
> paste(c('Bob', 'loves', 'Sally'), collapse = ' ')
[1] "Bob loves Sally"
John Miyamoto <[EMAIL PROTECTED]> writes:
>Suppose I have a character vector.
>
> x <- c("Bob", "loves", "Sally")
>
> I want to combine it into a single string: "Bob loves Sally"
paste(x,collapse=" ")
On Wed, 2 Apr 2003, John Miyamoto wrote:
> Dear Help,
>Suppose I have a character vector.
>
> x <- c("Bob", "loves", "Sally")
>
> I want to combine it into a single string: "Bob loves Sally" .
> paste(x) yields:
> paste(x)
> [1] "Bob" "loves" "Sally"
>
> The fo
The collapse argument does what you want:
x <- c("Bob", "loves", "Sally")
paste(c, collapse = " ")
Hope this helps,
Matt Wiener
-Original Message-
From: John Miyamoto [mailto:[EMAIL PROTECTED]
Sent: Wednesday, April 02, 2003 6:54 PM
To: R discussion group
Subject: [R] Combining the com
John Miyamoto wrote:
> Suppose I have a character vector.
> x <- c("Bob", "loves", "Sally")
>
> I want to combine it into a single string: "Bob loves Sally" .
> paste(x) yields:
> paste(x)
> [1] "Bob" "loves" "Sally"
>
Try:
> paste(x,collapse=" ")
and
> help(paste)
--Peter
-
John,
Try paste with collapse argument:
> x <- c("Bob", "loves", "Sally")
> paste(x,collapse=" ")
[1] "Bob loves Sally"
HTH
steve
John Miyamoto wrote:
> Dear Help,
>Suppose I have a character vector.
>
> x <- c("Bob", "loves", "Sally")
>
> I want to combine it into a single string: "Bob lo
> x <- c("Bob", "loves", "Sally")
> paste(x,collapse=" ")
[1] "Bob loves Sally"
best,
vito
- Original Message -
From: "John Miyamoto" <[EMAIL PROTECTED]>
To: "R discussion group" <[EMAIL PROTECTED]>
Sent: Thursday, April 03, 2003 1:54 AM
Subject: [R] Combining the components of a charac
On Thursday 03 Apr 2003 1:54 am, John Miyamoto wrote:
> Dear Help,
>Suppose I have a character vector.
>
> x <- c("Bob", "loves", "Sally")
>
> I want to combine it into a single string: "Bob loves Sally" .
y <- paste(c, collapse=" ")
best wishes
Ido
> Dear Help,
>Suppose I have a character vector.
>
> x <- c("Bob", "loves", "Sally")
>
> I want to combine it into a single string: "Bob loves Sally" .
> paste(x) yields:
> paste(x)
> [1] "Bob" "loves" "Sally"
>
R> x <- c("Bob", "loves", "Sally")
R> paste(x, collapse=" ")
[1] "Bob loves Sal
On Thursday 03 April 2003 01:54, John Miyamoto wrote:
> Dear Help,
>Suppose I have a character vector.
>
> x <- c("Bob", "loves", "Sally")
>
> I want to combine it into a single string: "Bob loves Sally" .
> paste(x) yields:
> paste(x)
> [1] "Bob" "loves" "Sally"
R> x <- c("Bob", "loves",
paste(x,collapse=" ")
-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Behalf Of John Miyamoto
Sent: Thursday, 3 April 2003 9:54 AM
To: R discussion group
Subject: [R] Combining the components of a character vector
Dear Help,
Suppose I have a character vector.
x <
John Miyamoto <[EMAIL PROTECTED]> writes:
> Dear Help,
>Suppose I have a character vector.
>
> x <- c("Bob", "loves", "Sally")
>
> I want to combine it into a single string: "Bob loves Sally" .
> paste(x) yields:
> paste(x)
> [1] "Bob" "loves" "Sally"
Like this:
> paste(x,collapse=" ")
20 matches
Mail list logo