Hi, I'm trying to concatenate my results for a for result I created. My teacher was trying to figure out a way to print results individually from. May 10, 2010 String Concatenation in R. String concatenation is a rather basic function – but my particular programming reflexes did not help me figure out how to do this in R. I tried the + and & operator, and even the operator to no avail. Also tried concat function no dice.
Posted by8 months ago
Archived
Hi, I'm trying to concatenate my results for a for result I created. My teacher was trying to figure out a way to print results individually from the sample #, to the entire sample, to the mean, and so far we have figured out that the print() function along with a sys.sleep(1) [In order to give the results time to display so they aren't all displayed at once allowing his students to view what is actually going on behind the scenes.] have worked for that purpose, but now he's wondering if there is a way to concatenate a string with the number. So for example, if I wanted the mean 'The mean of sample (Sample number [i]) is ... (mean)'
This is my code so far:
xbar5 <-rep(NA, 10)
for (i in 1:10){
x <-sample(survey$age, size =5)
xbar5[i] <- mean(x)
#Print out the sample number (1-10). I'm hoping to be able to print this out with the mean.
print(i)
#Wait.
Sys.sleep(2)
#Print out the entire sample.
print(x)
#Wait.
Sys.sleep(2)
#Print out the mean of that sample.
print(xbar5[i])
Sys.sleep(2)
}
6 comments
String concatenation
The function
concat
concatenates character vectors all together.concat0(.)
is a wrapper for concat(., sep = ')
. concat_(.)
is a wrapper for concat(., sep = '_')
.Usage
Arguments
One or more objects, to be converted to character vectors and concatenated.
character. The character to use to separate the result.
logical. If
TRUE
(the default), missing values are removed before concatenation.Value
Always a character value (vector of length
1
).See Also
paste
.Aliases
- concat
- concat0
- concat_
Examples
Community examples
![R Concatenate Strings R Concatenate Strings](/uploads/1/2/5/8/125865548/234860795.png)
API documentation