is.na and is.element

is.na can use which, it finds specific rows, is.element can't, it is designed to find NA in a whole table

d[is.na(d)] <- 0
is.element(NA,temp_city$city_name)

delete certain rows

df <- df[-c(1,2),]#drop discrete rows
df <- df[-c(1:2),]#drop continous rows

delete certain columns

trade_month_final <- trade_month_final[,-(2:3)]
shoppingmall_amap3 <- subset(shoppingmall_amap3,select=-c(origin_name))
shoppingmall_amap2 <- shoppingmall_amap2[,-c('origin_name')]
tmpdata <- data_set[ , !names(data_set) %in% c(“var1”, “var2”)]

grepl,unique and gsub

content_int<-content_int[!grepl('TRUE',content_int$store_name)]
content_int<-unique(content_int,by=c('store_name'))
content_int$store_name<-gsub['[(].*|[)].*','',content_int$store_name)]

build a row which has the same number of rows in the table

table_temp1$month <- month

remember, this only applies to numeric variables. When month is a data frame(like when it is calculated by aggregate function),we have to transfer it into numeric ones with as.numeric.

ave
city_statistic$group_freq<-ave(city_statistic$freq, city_statistic$group_final_id, FUN = sum)

这样每组的每个成员的记录行都会多一列相同的值,如上述函数按id汇总求freq的和,每一个id下的分店都有一个freq之和的属性

empty,character(0),NA,null
for character(0)
#rlang::is_empty()

If

if (x< 0.2){
   x <- x+1
   print("success!")
}else{
   x < x-1
   print("else success!")
}
For
for (k in k:length(file)){}
how to build a function in R
##' gettianmap
##'
##' Combine Repeated function
##'
##' URLencode & getURL & fromJSON & tryCatch
##'
##' @param url current URL address
##' @param timeout_set timeout value
##' @return amap
##' @author t.s.helianthus <\url{http://helianthus-code.lofter.com}>
##' @examples amap <- getMapData(url = 'http://restapi.amap.com/v3/ip?key=389880a06e3f893ea46036f030c94700')
##' @import RCurl
##' @import rjson
##' @import httr
##' @export gettianmap <- function (url, timeout_set = 15) {
tianmap <- NULL;
url <- URLencode(enc2utf8(url))
connect <- ''
# print(url)
msg.load <- tryCatch ({
connect <- getURL(url,httpheader=myheader,.encoding="utf-8", .opts = list(timeout = timeout_set, maxredirs = 2))
tianmap <- fromJSON(connect)
msg.load <- "TRUE"
}, error = function (e) {
"FALSE"
}
)
if (msg.load == 'FALSE') {
print('error >> reload')
msg.load <- tryCatch({
tianmap <- content(GET(url,verbose(),timeout(timeout_set),add_headers(myheader)))
msg.load <- "TRUE"
}, error = function(e) {
"FALSE"
})
}
#if ( length(grep('too fast',amap)) == 1) {print('********too_fast********');print(stop_curl)} if ( length(grep('too fast',tianmap)) == 1) {print('********too_fast********');install.packages("ggplot2")}
if (msg.load == 'FALSE') {tianmap <- NULL;print('reload false >> NULL')}
return(tianmap)
}
循环next和break
for(i in 1:5){ 
  if(i=3){
      break; 
  }
  print(i);
}
for(i in 1:5){ 
  if(i=3){
      next; 
  }
  print(i);
}

ggplot2

官方文档:https://ggplot2.tidyverse.org/reference/scale_manual.html

详细柱形图:https://www.r-bloggers.com/how-to-make-a-histogram-with-ggplot2/

添加横竖线:cnblogs.com/wkslearner/p/5697471.html

R cookbook:http://www.cookbook-r.com/Graphs/

所有关于坐标轴的信息:https://blog.csdn.net/Bone_ACE/article/details/47427453

查看图像的构造 ,如颜色

g <- ggplot_build(p)
unique(g$data[[1]]$color)

R语言基本操作的更多相关文章

  1. R 语言基本操作(基本信息的查看、与本地文件系统交互、编译器版本升级)

    0. 信息及路径的查看 getwd() ⇒ 查看路径: setwd() ⇒ 设置路径: .libPaths() ⇒ R 语言库所在的位置: sessionInfo() ⇒ 查询版本及系统和库等信息: ...

  2. R语言基本操作函数---变量的基本操作

    1.变量变换        as.array(x),as.data.frame(x),as.numeric(x),as.logical(x),as.complex(x),as.character(x) ...

  3. R语言基本操作函数(1)变量的基本操作

    1.变量变换        as.array(x),as.data.frame(x),as.numeric(x),as.logical(x),as.complex(x),as.character(x) ...

  4. 【统计与建模】R语言基本操作

    # vec <- rep( seq(1,5,by=0.5),3) # vec <- seq( 1 , 10 , by = 1 ) # min(vec) #最小值 # max(vec) #最 ...

  5. R语言入门:使用RStudio的基本操作

    R语言在人工智能,统计学,机器学习,量化投资,以及生物信息学方面有着十分广泛的运用.也是我大学的必修课,因此这里梳理一些有关R语言的知识点,做做记录. 首先我们需要知道R语言的工作区域,R语言默认的工 ...

  6. 几种经典排序算法的R语言描述

    1.数据准备 # 测试数组 vector = c(,,,,,,,,,,,,,,) vector ## [] 2.R语言内置排序函数 在R中和排序相关的函数主要有三个:sort(),rank(),ord ...

  7. R语言介绍

    R语言简介 R语言是一种为统计计算和图形显示而设计的语言环境,是贝尔实验室(Bell Laboratories)的Rick Becker.John Chambers和Allan Wilks开发的S语言 ...

  8. 数据分析R语言1

    数据分析R语言 无意中发现网上的一个数据分析R应用教程,看了几集感觉还不错,本文做一个学习笔记(知识点来源:视频内容+R实战+自己的理解),视频详细的信息请参考http://www.itao521.c ...

  9. R语言︱SNA-社会关系网络 R语言实现专题(基础篇)(一)

    每每以为攀得众山小,可.每每又切实来到起点,大牛们,缓缓脚步来俺笔记葩分享一下吧,please~ --------------------------- 笔者寄语:这里所有的应用代码都来自与igrap ...

随机推荐

  1. 我为什么要用CSDN博客?

    在今年的二月份,因老师说由于学习需要,我怀着抵触的情绪开通了之前闻所未闻的CSDN博客. 三月六号我发了第一篇原创文章,说实话感觉没什么意思,只是在完成老师留给的任务.接下来的几周一直按着老师的要求不 ...

  2. 5——PHP逻辑运算符&&唯一的三元运算符

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  3. Java工作流引擎结合可视化表单开发,10分钟完成一个业务流程发布

    回忆以前工作流引擎的应用,感觉历历在目啊!当初公司接了一个项目关于政府单位公文流转的管理系统,一开始客户跟我画了十多张业务流程图.话说这十多张业务流程图,涉及的业务范围还蛮多,像用审批授权,开通流程, ...

  4. Spring常见注解

    @Autowired @Resource @Component:类加上@Component注解,即表明此类是bean @Aspect 注解表示这是一个切面 @Around(value = " ...

  5. PHP文件上传 (以上传txt文件为例)

    1.前端代码 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <ti ...

  6. 用vue + leancloud开发一个免费的博客

    项目地址 https://github.com/Fee-ing/Fe... 在线预览 在线预览地址: 搭建免费博客

  7. 三年前端,面试思考(头条蚂蚁美团offer)

    小鱼儿本人985本科,软件工程专业,前端.工作三年半,第一家创业公司,半年.第二家前端技术不错的公司,两年半.第三家,个人创业半年.可以看出,我是个很喜欢折腾的人,大学期间也做过很多项目,非常愿意参与 ...

  8. webstorm 提示 "scanning files to index..." 一直不能编译的问题

    先说一下我的操作过程吧: 下载公司的vue项目后,要用到webpack打包工具,需要按照package.json安装一些依赖,我使用了镜像后,npm install模块时候生成了一个 node_mod ...

  9. HTTP入门(一):在Bash中curl查看请求与响应

    HTTP入门(一):在Bash中curl查看请求与响应 本文简单总结HTTP的请求与响应. 本文主要目的是对学习内容进行总结以及方便日后查阅. 详细教程和原理可以参考HTTP文档(MDN). 本文版权 ...

  10. iTerm2 都不会用,还敢自称老司机?(上)

    对于需要长期与终端打交道的工程师来说,拥有一款称手的终端管理器是很有必要的,对于 Windows 用户来说,最好的选择是 Xshell,这个大家都没有异议.但对于 MacOS 用户来说,仍然毋庸置疑, ...