- 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:

推薦閱讀
- 腦動力:Linux指令速查效率手冊
- Dreamweaver CS3網頁制作融會貫通
- Drupal 7 Multilingual Sites
- Learning Apache Cassandra(Second Edition)
- Hands-On Linux for Architects
- 大數據安全與隱私保護
- 數據挖掘方法及天體光譜挖掘技術
- 大型數據庫管理系統技術、應用與實例分析:SQL Server 2005
- 中國戰略性新興產業研究與發展·工業機器人
- 單片機C語言應用100例
- 單片機技能與實訓
- 機器人人工智能
- Linux系統下C程序開發詳解
- Building Google Cloud Platform Solutions
- 基于Proteus的PIC單片機C語言程序設計與仿真