Use the R language to replace a vector with a string

Source: Internet
Author: User

Replace the vector, A, b with a string, where:

A=c (1,2,3,4)
b=c (2,3,4,5)

In order to convert it into a string can be achieved by introducing the package Stringr, using the Str_c implementation, using paste also can achieve the purpose, as follows:

Library (Stringr)
a_b=str_c (a,b,collapse= ")
paste (a,b,sep=")

The output is:

[1] "12233445"

In the actual data processing can be used to build a federated index, such as the data frame needed to join the index column into a column, it can be more convenient in practice, to avoid a lot of trouble, but it is important to note that at the end of each column with a character such as a null character to ensure one by one mapping. For example, the data for the first two rows of the data frame are:

  A1 A2 A3 A4
1  1  1  4
2 1 each  1  5

If you use the first three columns, the index is A1,A2,A3. If you do not add a special word, the Fu Zeti line and the second line are concatenated with the following characters:

[1] "1111"

The indexes are the same, so you need to add special characters to avoid this, such as after joining a space after two lines of data are connected:

[1] "1 1"
[2] "1 11 1"

These two strings are not the same.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.