美文网首页
Statistical Computing with R学到的知

Statistical Computing with R学到的知

作者: kkkkkkang | 来源:发表于2022-01-25 15:29 被阅读0次

不知道怎么敲,但常用到的帮助

?Syntax

:: :::  access variables in a namespace
$ @ component / slot extraction
[ [[    indexing
^   exponentiation (right to left)
- + unary minus and plus
:   sequence operator
%any% |>    special operators (including %% and %/%)
* / multiply, divide
+ - (binary) add, subtract
< > <= >= == != ordering and comparison
!   negation
& &&    and
| ||    or
~   as in formulae
-> ->>  rightwards assignment
<- <<-  assignment (right to left)
=   assignment (right to left)
?   help (unary and binary)

# 其它的不一一列举了
?Arithmetic
?Comparison #relational operators
?Extract #operators on vectors and arrays
?Control #control flow
?Logic #logical operators

特殊符号的帮助文档如何获取?

# 加上双引号
> ?%/%
Error: unexpected SPECIAL in "?%/%"
> ?"%/%"
# 或者直接问Arithmetic,有很多
> ?Arithmetic

Arithmetic {base}   R Documentation
Arithmetic Operators
Description
These unary and binary operators perform arithmetic on numeric or complex vectors (or objects which can be coerced to them).

Usage
+ x
- x
x + y
x - y
x * y
x / y
x ^ y
x %% y
x %/% y

查看R可用的颜色,DAAG包

install.package("DAAG")
library(DAAG)
show.colors(type = c("singles"))
show.colors(type = c("shades"))
show.colors(type = c("gray"))
singles
shades
gray

然后就可以选里面颜色用了,记不住可以把这个图当桌面。

ToothGrowth$dose <- as.factor(ToothGrowth$dose)
head(ToothGrowth)
library(ggplot2)
library(DAAG)
ggplot(ToothGrowth, aes(x=dose, y=len)) + 
    geom_boxplot()
ggplot(ToothGrowth, aes(x=dose, y=len,color=dose)) + 
    geom_boxplot()+
    scale_color_manual(values=c("magenta", "magenta3", "magenta4"))
image.png

导入文件时,不作为因子,as.is = TRUE

fileloc <- "https://archive.ics.uci.edu/ml/machine-learning-databases/
auto-mpg/auto-mpg.data"
df <- read.table(file = fileloc, na.strings = "?", as.is = TRUE)
# na.strings指定哪个符号被认为是NA

按照概率取样

> x <- sample(1:3, size = 100, replace = TRUE,
prob = c(.2, .3, .5))
> table(x)
x
1 2 3
17 35 48

相关文章

网友评论

      本文标题:Statistical Computing with R学到的知

      本文链接:https://www.haomeiwen.com/subject/kmrbhrtx.html