Introduction to R language-which black technologies you don't know

No matter how short the document is, there must be a table of contents

00 Introduction

In the introduction of R language, you will encounter various functions for processing data to build a model. Today, I will introduce the functions that have been ignored by everyone in programming.

1、()

()Let me turn it into a function, let's demonstrate his function:

> x <- 1+1
> (x <- 1+1)
[1] 2
> x <- "123"
> (x <- "123")
[1] "123"

The function of this is to assign and output. He can replace the following commands:

x <- 对象
x

Haha, okay, maybe someone has seen it and used it all the time, but this function introduced below should be used by very few people. If you leave a comment in the comment area, it's all a lot of digging (of course I don't need it).

2. "Operational symbols" (,)

??? What kind of fairy function is this? Don't panic the following example.

> "+"(2,1)
[1] 3
> "-"(2,1)
[1] 1
> "*"(2,2)
[1] 4
> "/"(2,2)
[1] 1

I won't explain much after seeing the example. Of course, this idea can also be used in the following way.

"sum"(52,4,8)

em ... what's the use. It's useless. After all, if it's useful, it will be known to everyone. But I am definitely unwilling to explore, and still verify the efficiency of this form.

> system.time(
+ for(i in 1:10000){
+   x <- 1:1000
+   "<-"(y,"^"(x,x))
+ }
+ )
用户 系统 流逝 
1.85 0.00 1.84 
> system.time(
+ for(i in 1:10000){
+   x <- 1:1000
+   y <- x^x
+ }
+ )
用户 系统 流逝 
1.83 0.02 1.84 

Confirmed the eyes, it really is no difference.

3. Summary

You can see that the friends here are endless love of R language. Do you have any R language black technology gameplay? Welcome to leave a comment and share it.

Published 30 original articles · praised 87 · 30,000+ views

Guess you like

Origin blog.csdn.net/weixin_46111814/article/details/105620397