In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
R language how to distinguish between paste () and cat (), many novices are not very clear about this, in order to help you solve this problem, the following editor will explain for you in detail, people with this need can come to learn, I hope you can get something.
In practice, it is often necessary to concatenate multiple strings into one. The paste () function and cat () are used to connect multiple character vectors. These two functions use spaces as the default delimiter.
Reproduction of classic examples of paste ()
> paste ("Hello", "China")
[1] "Hello China"
> paste ("Hello", "China", sep = "-")
[1] "Hello-China"
# if you don't need a delimiter, you can set sep= "" or use paste0 ()
> paste0 ("Hello", "China")
[1] "HelloChina"
Let's take a look at the cat () function
> cat ("Hello", "China")
Hello China
> cat ("Hello", "China", sep = "-")
Hello-China
> cat ("Hello", "China", sep = "")
HelloChina
At first glance, they can all be used for connection strings, and there is no difference in running results.
Don't worry, look further down.
> string1 string1
NULL
> string2 string2
[1] "Hello China"
Can you see the difference? The difference is that cat () only prints the string in the console, but paste () can return the string to create a new character vector for later use. Cat () prints out the concatenated string, but returns NULL, indicating that the system does not store the string printed by cat (), and it is impossible to call it later!
Let's take a look at how paste () and cat () behave when dealing with multi-element vectors.
> paste (c ("C", "D"), c ("E", "F"))
[1] "C E"D F"
By automatically matching elements, paste () first executes paste ("C", "E"), then paste ("D", "F"), and finally forms a character vector with two elements. Question1: what if you want to display the result "C E D F" in the same string? Will you still not understand after reading the next example?
> String3 String3
[1] "ce\ nD F"
This code is to let them appear in two lines, set collapse to\ n (that is, newline character), in the displayed results do not see the effect of line feeds, then call the cat () function, the effect lever drop.
> cat (String3)
C E
D F
Do you have the answer to question 1?
Is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.