- Hands-On Geospatial Analysis with R and QGIS
- Shammunul Islam
- 130字
- 2021-06-10 18:44:24
Functions in R
We can also achieve the previous result by using a function. Let's name this function square:
square = function(data){
for(price in data){
print(price^2)
}
}
Now call the function as follows:
square(all_prices4$jan_price)
The following output also shows the squared price of jan_price:

Now suppose we want to have the ability to take elements to any power, not just square. We can attain it by making a little tweak to the function:
power_function = function(data, power){
for(price in data){
print(price^power)
}
}
Now suppose we want to take the power of 4 for the price in June, we can do the following:
power_function(all_prices4$june_price, 4)
We can see that the june_price column is taken to the fourth power as follows:

推薦閱讀
- 課課通計(jì)算機(jī)原理
- 電力自動(dòng)化實(shí)用技術(shù)問答
- 21小時(shí)學(xué)通AutoCAD
- Mastering Salesforce CRM Administration
- 機(jī)器人智能運(yùn)動(dòng)規(guī)劃技術(shù)
- Security Automation with Ansible 2
- PHP開發(fā)手冊(cè)
- Data Wrangling with Python
- 分布式多媒體計(jì)算機(jī)系統(tǒng)
- 數(shù)據(jù)挖掘方法及天體光譜挖掘技術(shù)
- Visual C++編程全能詞典
- Android游戲開發(fā)案例與關(guān)鍵技術(shù)
- 悟透AutoCAD 2009完全自學(xué)手冊(cè)
- 智能生產(chǎn)線的重構(gòu)方法
- 過程控制系統(tǒng)