In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article introduces you what are the relevant experiences in R language, the content is very detailed, interested friends can refer to, I hope it can be helpful to you.
Some sharing related to function in R
Text:
The essence of function is text substitution.
Function can be ubiquitous in R, such as read_excel () and write.csv mentioned in the previous article, as well as mean () and median () included in base, all of which are function. So function can be understood as a series of sentences packaged in order to solve a problem or a series of problems. It feels like a several-degree equation in high school mathematics, entering the value of x will get a specific value of y.
There are two main sources of function.
One is written by others, that is, functions that have been written by others in base or other package.
The other is written by yourself, also known as custom function, according to your actual problem to solve, you can write a piece of code to meet your specific needs and package it in a function statement to generate your own function. How to write a function yourself, and the level at which function can solve problems, and the syntax and syntax of function itself, to some extent, can reflect or test the code level of the current writer.
The syntax of function consists of fixed statements + parameters + problem-solving code. It is divided into these three parts, and the need for research is the second and third parts.
How to write a custom function. Roughly divided into the following steps:
First, make clear the purpose of writing function. There is no alternative, whether you really need a custom function to solve the problem. Consider the cost-effective ratio, whether it is really necessary to take the time to develop a piece of code, are there any immortals who have developed a good package for similar problems that can be called directly? Wait. After confirming that you really need to write, start developing the code, in fact, the process is very happy.
Second, the train of thought of writing function. Divide and rule, break down one by one, and then unify the mountains and rivers. The problem is usually not that complicated, and the reason why it becomes very complicated is generally due to confusion of thinking. The problem can be split and solved separately, and the final integration result will be ok. If, on the contrary, the problem becomes more complicated, it is putting the cart before the horse and the loss outweighs the gain.
Third, the steps of writing function. It is roughly as follows
1: just write a piece of code that can solve the target problem, that is, "hard" code.
2: simplify and refine the code.
3: replace the key data or variable in the "hard" code with parameters to achieve text replacement.
4: a small-scale test of the generated custom function.
5: according to the actual environment, simulate the real situation that you may encounter, test the elasticity and effect of function on a large scale, and fine-tune it.
Fourth: matters needing attention.
1: use as few loops as possible, loops will pull down the running efficiency, especially when the amount of data is very large, it will be slow and touching.
2: make statements as concise as possible, reduce redundant code, and don't beat around the bush, which is good for yourself or for people who read the code.
3: you can try to call other package functions in your code to improve efficiency, get twice the result with half the effort, and see further on the shoulders of giants.
4: if you consider future extensibility, try to leave plenty of room in the writing process, avoid using some hard text in the intermediate steps, and try to use code that can run the results automatically.
5: the parameters should be refined and excellent, and you should think twice before setting.
Just as SAS bosses are crazy about developing their own macro, R bosses are crazily developing their own function. The world of bosses is always so crazy.
What is the relevant experience in R language to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
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