楼主: Lisrelchen
4139 58

R Cookbook [推广有奖]

  • 0关注
  • 62粉丝

VIP

院士

67%

还不是VIP/贵宾

-

TA的文库  其他...

Bayesian NewOccidental

Spatial Data Analysis

东西方数据挖掘

威望
0
论坛币
49957 个
通用积分
79.5487
学术水平
253 点
热心指数
300 点
信用等级
208 点
经验
41518 点
帖子
3256
精华
14
在线时间
766 小时
注册时间
2006-5-4
最后登录
2022-11-6

相似文件 换一批

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币

  • R Cookbook
  • By: Paul Teetor

  • Publisher: O'Reilly Media, Inc.

  • Pub. Date: March 15, 2011

  • Print ISBN-13: 978-0-596-80915-7

  • Pages in Print Edition: 438

  • Subscriber Rating: [6 Ratings] Subscriber Reviews


本帖隐藏的内容

R Cookbook.rar (3.14 MB) 本附件包括:
  • R Cookbook.pdf

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

关键词:Cookbook Book Cook COO Subscriber Media

本帖被以下文库推荐

沙发
Lisrelchen 发表于 2015-9-6 11:42:58 |只看作者 |坛友微信交流群
  1. Printing Something

  2. Problem
  3. You want to display the value of a variable or expression.

  4. Solution
  5. If you simply enter the variable name or expression at the command prompt, R will print its value. Use the print function for generic printing of any object. Use the cat function for producing custom formatted output
复制代码

使用道具

藤椅
Lisrelchen 发表于 2015-9-6 11:43:44 |只看作者 |坛友微信交流群
  1. Setting Variables

  2. Problem
  3. You want to save a value in a variable.

  4. Solution
  5. Use the assignment operator (<-). There is no need to declare your variable first:

  6. > x <- 3
复制代码

使用道具

板凳
Lisrelchen 发表于 2015-9-6 11:45:47 |只看作者 |坛友微信交流群
  1. Listing Variables

  2. Problem
  3. You want to know what variables and functions are defined in your workspace.

  4. Solution
  5. Use the ls function. Use ls.str for more details about each variable.

  6. Discussion
  7. The ls function displays the names of objects in your workspace:

  8. > x <- 10
  9. > y <- 50
  10. > z <- c("three", "blind", "mice")
  11. > f <- function(n,p) sqrt(p*(1-p)/n)
  12. > ls()
复制代码

使用道具

报纸
Lisrelchen 发表于 2015-9-6 11:46:35 |只看作者 |坛友微信交流群
  1. Deleting Variables

  2. Problem
  3. You want to remove unneeded variables or functions from your workspace or to erase its contents completely.

  4. Solution
  5. Use the rm function.

  6. Discussion
  7. Your workspace can get cluttered quickly. The rm function removes, permanently, one or more objects from the workspace:

  8. > x <- 2*pi
  9. > x
  10. [1] 6.283185
  11. > rm(x)
  12. > x
  13. Error: object "x" not found
复制代码

使用道具

地板
Lisrelchen 发表于 2015-9-6 11:47:25 |只看作者 |坛友微信交流群
  1. Creating a Vector

  2. Problem
  3. You want to create a vector.

  4. Solution
  5. Use the c(...) operator to construct a vector from given values.

  6. Discussion
  7. Vectors are a central component of R, not just another data structure. A vector can contain either numbers, strings, or logical values but not a mixture.

  8. The c(...) operator can construct a vector from simple elements:

  9. > c(1,1,2,3,5,8,13,21)
  10. [1]  1  1  2  3  5  8 13 21
  11. > c(1*pi, 2*pi, 3*pi, 4*pi)
  12. [1]  3.141593  6.283185  9.424778 12.566371
  13. > c("Everyone", "loves", "stats.")
  14. [1] "Everyone" "loves"    "stats."
  15. > c(TRUE,TRUE,FALSE,TRUE)
  16. [1]  TRUE  TRUE FALSE  TRUE
  17. If the arguments to c(...) are themselves vectors, it flattens them and combines them into one single vector:

  18. > v1 <- c(1,2,3)
  19. > v2 <- c(4,5,6)
  20. > c(v1,v2)
  21. [1] 1 2 3 4 5 6
  22. Vectors cannot contain a mix of data types, such as numbers and strings. If you create a vector from mixed elements, R will try to accommodate you by converting one of them:

  23. > v1 <- c(1,2,3)
  24. > v3 <- c("A","B","C")
  25. > c(v1,v3)
复制代码

使用道具

7
Lisrelchen 发表于 2015-9-6 11:48:36 |只看作者 |坛友微信交流群
  1. Computing Basic Statistics

  2. Problem
  3. You want to calculate basic statistics: mean, median, standard deviation, variance, correlation, or covariance.

  4. Solution
  5. Use one of these functions as applies, assuming that x and y are vectors:

  6. mean(x)

  7. median(x)

  8. sd(x)

  9. var(x)

  10. cor(x, y)

  11. cov(x, y)

  12. Discussion
  13. When I first opened the documentation for R, I begin searching for material entitled “Procedures for Calculating Standard Deviation.” I figured that such an important topic would likely require a whole chapter.

  14. It’s not that complicated.

  15. Standard deviation and other basic statistics are calculated by simple functions. Ordinarily, the function argument is a vector of numbers and the function returns the calculated statistic:

  16. > x <- c(0,1,1,2,3,5,8,13,21,34)
  17. > mean(x)
  18. [1] 8.8
  19. > median(x)
  20. [1] 4
  21. > sd(x)
  22. [1] 11.03328
  23. > var(x)
  24. [1] 121.7333
  25. The sd function calculates the sample standard deviation, and var calculates the sample variance.

  26. The cor and cov functions can calculate the correlation and covariance, respectively, between two vectors:

  27. > x <- c(0,1,1,2,3,5,8,13,21,34)
  28. > y <- log(x+1)
  29. > cor(x,y)
  30. [1] 0.9068053
  31. > cov(x,y)
  32. [1] 11.49988
复制代码

使用道具

8
Lisrelchen 发表于 2015-9-6 11:49:19 |只看作者 |坛友微信交流群
  1. Creating Sequences

  2. Problem
  3. You want to create a sequence of numbers.

  4. Solution
  5. Use an n:m expression to create the simple sequence n, n+1, n+2, ..., m:

  6. > 1:5
  7. [1] 1 2 3 4 5
  8. Use the seq function for sequences with an increment other than 1:

  9. > seq(from=1, to=5, by=2)
  10. [1] 1 3 5
  11. Use the rep function to create a series of repeated values:

  12. > rep(1, times=5)
  13. [1] 1 1 1 1 1
复制代码

使用道具

9
Lisrelchen 发表于 2015-9-6 11:57:38 |只看作者 |坛友微信交流群
  1. Comparing Vectors

  2. Problem
  3. You want to compare two vectors or you want to compare an entire vector against a scalar.

  4. Solution
  5. The comparison operators (==, !=, <, >, <=, >=) can perform an element-by-element comparison of two vectors. They can also compare a vector’s element against a scalar. The result is a vector of logical values in which each value is the result of one element-wise comparison.

  6. Discussion
  7. R has two logical values, TRUE and FALSE. These are often called Boolean values in other programming languages.

  8. The comparison operators compare two values and return TRUE or FALSE, depending upon the result of the comparison:

  9. > a <- 3
  10. > a == pi     # Test for equality
  11. [1] FALSE
  12. > a != pi     # Test for inequality
  13. [1] TRUE
  14. > a < pi
  15. [1] TRUE
  16. > a > pi
  17. [1] FALSE
  18. > a <= pi
  19. [1] TRUE
  20. > a >= pi
  21. [1] FALSE
复制代码

使用道具

10
Lisrelchen 发表于 2015-9-6 11:59:15 |只看作者 |坛友微信交流群
  1. Selecting Vector Elements

  2. Problem
  3. You want to extract one or more elements from a vector.

  4. Solution
  5. Select the indexing technique appropriate for your problem:

  6. Use square brackets to select vector elements by their position, such as v[3] for the third element of v.

  7. Use negative indexes to exclude elements.

  8. Use a vector of indexes to select multiple values.

  9. Use a logical vector to select elements based on a condition.

  10. Use names to access named elements.
复制代码

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 19:53