R语言中的编程中double什么意思思?


选择擅长的领域继续答题?
{@each tagList as item}
${item.tagName}
{@/each}
手机回答更方便,互动更有趣,下载APP
提交成功是否继续回答问题?
手机回答更方便,互动更有趣,下载APP
展开全部double是c语言中的双精度浮点数类型,用来表示实数。1定义:doublevar_name;这样定义一个名字为var_name的double类型变量。2赋值:var_name=100.325;同其它类型的赋值语句一样,对var_name赋值用=运算符,右侧可以是任意表达式。3输入:scanf("%lf",&var_name);%lf格式符号对应double,可以用来对double类型输入,以下输出类似。4输出:printf("%lf",var_name);已赞过已踩过你对这个回答的评价是?评论
收起
展开全部双精度浮点型数据,位数应该因编译环境不同而不同吧。
收起
更多回答(1)
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
为你推荐:
下载百度知道APP,抢鲜体验使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。扫描二维码下载
×个人、企业类侵权投诉
违法有害信息,请在下方选择后提交
类别色情低俗
涉嫌违法犯罪
时政信息不实
垃圾广告
低质灌水
我们会通过消息、邮箱等方式尽快将举报结果通知您。说明
做任务开宝箱累计完成0
个任务
10任务
50任务
100任务
200任务
任务列表加载中...
r语言是高级编程语言R is an open source programming language and software environment for statistical computing and graphics. It is one of the primary languages used by data scientists and statisticians alike. It is supported by the R Foundation for Statistical Computing and a large community of open source developers. Since R utilized a command line interface, there can be a steep learning curve for some individuals who are used to using GUI focused programs such as SPSS and SAS so extensions to R such as RStudio can be highly beneficial. Since R is an open source program and freely available, there can a large attraction for academics whose access to statistical programs are regulated through their association to various colleges or universities. R是用于统计计算和图形的开源编程语言和软件环境。 它是数据科学家和统计学家使用的主要语言之一。 它由R的统计计算基金会和一个大型的开源开发者社区提供支持。 由于R使用命令行界面,对于习惯使用GUI集中程序(例如SPSS和SAS)的某些人来说,学习曲线可能会很陡峭,因此对R的扩展(例如RStudio)可能会非常有益。 由于R是一个开放源代码计划,可免费获得,因此对于那些通过与各个学院或大学的联系而对统计程序的访问进行管理的学者,可能会产生很大的吸引力。
安装 (Installation)The first thing you need to get started with R is to download it from its official site according to your operating system. 开始使用R的第一件事是根据您的操作系统从其官方网站下载它。
流行的R工具和软件包 (Popular R Tools and Packages)RStudio is an integrated development environment (IDE) for R. It includes a console, syntax-highlighting editor that supports direct code execution, as well as tools for plotting, history, debugging and workspace management. RStudio是R的集成开发环境(IDE)。它包含一个控制台,语法突出显示的编辑器,支持直接执行代码,以及用于绘图,历史记录,调试和工作区管理的工具。 The Comprehensive R Archive Network (CRAN) is a leading source for R tools and resources. 综合R存档网络(CRAN)是R工具和资源的主要来源。 Tidyverse is an opinionated collection of R packages designed for data science like ggplot2, dplyr, readr, tidyr, purr, tibble. Tidyverse是为数据科学而设计的R软件包的自有集合,例如ggplot2,dplyr,readr,tidyr,purr,tibble。 data.table is an implementation of base data.frame focused on improved performance and terse, flexible syntax. data.table是基础data.frame的实现,专注于提高性能和简洁灵活的语法。 Shiny framework for building dashboard style web apps in R. 用于在R中构建仪表板样式的Web应用程序的闪亮框架。
R中的数据类型 (Data Types in R) 向量 (Vector)It is a sequence of data elements of the same basic type. For example: 它是相同基本类型的数据元素序列。 例如: > o <- c(1,2,5.3,6,-2,4)
# Numeric vector
> p <- c("one","two","three","four","five","six")
# Character vector
> q <- c(TRUE,TRUE,FALSE,TRUE,FALSE,TRUE)
# Logical vector
> o;p;q
[1]
1.0
2.0
5.3
6.0 -2.0
4.0
[1] "one"
"two"
"three" "four"
"five"
"six"
[1]
TRUE
TRUE FALSE
TRUE FALSE 矩阵 (Matrix)It is a two-dimensional rectangular data set. The components in a matrix also must be of the same basic type like vector. For example: 它是一个二维矩形数据集。 矩阵中的成分也必须是相同的基本类型,例如向量。 例如: > m = matrix( c('a','a','b','c','b','a'), nrow = 2, ncol = 3, byrow = TRUE)
> m
>[,1] [,2] [,3]
[1,] "a"
"a"
"b"
[2,] "c"
"b"
"a" 数据框 (Data Frame)It is more general than a matrix, in that different columns can have different basic data types. For example: 它比矩阵更通用,因为不同的列可以具有不同的基本数据类型。 例如: > d <- c(1,2,3,4)
> e <- c("red", "white", "red", NA)
> f <- c(TRUE,TRUE,TRUE,FALSE)
> mydata <- data.frame(d,e,f)
> names(mydata) <- c("ID","Color","Passed")
> mydata 清单 (Lists)It is an R-object which can contain many different types of elements inside it like vectors, functions and even another list inside it. For example: 它是一个R对象,其中可以包含许多不同类型的元素,例如矢量,函数,甚至其中的另一个列表。 例如: > list1 <- list(c(2,5,3),21.3,sin)
> list1
[[1]]
[1] 2 5 3
[[2]]
[1] 21.3
[[3]]
function (x)
.Primitive("sin") R中的功能 (Functions in R)A function allows you to define a reusable block of code that can be executed many times within your program. 函数允许您定义一个可重用的代码块,该代码块可以在程序中多次执行。 Functions can be named and called repeatedly or can be run anonymously in place (similar to lambda functions in python). 函数可以重复命名和调用,也可以在本地匿名运行(类似于python中的lambda函数)。 Developing full understanding of R functions requires understanding of environments. Environments are simply a way to manage objects. An example of environments in action is that you can use a redundant variable name within a function, that won’t be affected if the larger runtime already has the same variable. Additionally, if a function calls a variable not defined within the function it will check the higher level environment for that variable. 全面理解R功能需要了解环境。 环境只是管理对象的一种方式。 实际环境的一个示例是,您可以在函数内使用冗余变量名,如果较大的运行时已经具有相同的变量,则该变量名不会受到影响。 此外,如果函数调用该函数中未定义的变量,则它将检查该变量的高级环境。
句法 (Syntax)In R, a function definition has the following features: 在R中,函数定义具有以下功能: The keyword function 关键字function a function name 函数名称 input parameters (optional) 输入参数(可选) some block of code to execute 一些要执行的代码块 a return statement (optional) 返回语句(可选) # a function with no parameters or returned values
sayHello() = function(){
"Hello!"
}
sayHello()
# calls the function, 'Hello!' is printed to the console
# a function with a parameter
helloWithName = function(name){
paste0("Hello, ", name, "!")
}
helloWithName("Ada")
# calls the function, 'Hello, Ada!' is printed to the console
# a function with multiple parameters with a return statement
multiply = function(val1, val2){
val1 * val2
}
multiply(3, 5)
# prints 15 to the consoleFunctions are blocks of code that can be reused simply by calling the function. This enables simple, elegant code reuse without explicitly re-writing sections of code. This makes code both more readable, makes for easier debugging, and limits typing errors. 函数是可以简单地通过调用函数重用的代码块。 这样就可以简单,优雅地重用代码,而无需显式重写代码部分。 这使代码更易读,调试更轻松,并减少了键入错误。 Functions in R are created using the function keyword, along with a function name and function parameters inside parentheses. R中的function是使用function关键字以及括号内的函数名称和函数参数创建的。 The return() function can be used by the function to return a value, and is typically used to force early termination of a function with a returned value. Alternatively, the function will return the final printed value. 函数可以使用return()函数来返回值,并且通常用于强制使用返回的值提前终止函数。 或者,该函数将返回最终的打印值。 # return a value explicitly or simply by printing
sum = function(a, b){
c = a + b
return(c)
}
sum = function(a, b){
a + b
}
result = sum(1, 2)
# result = 3You can also define default values for the parameters, which R will use when a variable is not specified during function call. 您还可以定义参数的默认值,当在函数调用期间未指定变量时,R将使用该默认值。 sum = function(a, b = 3){
a + b
}
result = sum(a = 1)
# result = 4You can also pass the parameters in the order you want, using the name of the parameter. 您还可以使用参数名称以所需顺序传递参数。 result = sum(b=2, a=2)
# result = 4R can also accept additional, optional parameters with ’…’ R还可以接受带有“…”的其他可选参数 sum = function(a, b, ...){
a + b + ...
}
sum(1, 2, 3) #returns 6Functions can also be run anonymously. These are very useful in combination with the ‘apply’ family of functions. 函数也可以匿名运行。 这些功能与“应用”功能系列结合使用非常有用。 # loop through 1, 2, 3 - add 1 to each
sapply(1:3,
function(i){
i + 1
}) 笔记 (Notes)If a function definition includes arguments without default values specified, values for those values must be included. 如果函数定义包含未指定默认值的参数,则必须包含这些值的值。 sum = function(a, b = 3){
a + b
}
sum(b = 2) # Error in sum(b = 2) : argument "a" is missing, with no defaultVariables defined within a function only exist within the scope of that function, but will check larger environment if variable not specified 在函数中定义的变量仅存在于该函数的范围内,但如果未指定变量,则将检查较大的环境 double = function(a){
a * 2
}
double(x)
# Error in double(x) : object 'x' not found
double = function(){
a * 2
}
a = 3
double() # 6 R中的内置函数 (In-built functions in R)R comes with many functions that you can use to do sophisticated tasks like random sampling. R附带了许多函数,可用于执行复杂的任务,例如随机采样。 For example, you can round a number with the round(), or calculate its factorial with the factorial(). 例如,您可以使用round()将数字round() ,或者使用factorial()计算其阶乘。 > round(4.147)
[1] 4
> factorial(3)
[1] 6
> round(mean(1:6))
[1] 4> sample(x = 1:4, size = 2)
[] 4 2
> sample(x = die, size = 1)
[] 3
>dice <- sample(die, size = 2, replace = TRUE)
>dice
[1] 2 4
>sum(dice)
[1] 6If you’re not sure which names to use with a function, you can look up the function’s arguments with args. 如果不确定函数要使用的名称,可以使用args查找函数的参数。 > args(round)
[1] function(x, digits=0) R中的对象 (Objects in R)R allows to save the data by storing it inside an R object. R允许通过将数据存储在R对象中来保存数据。
什么是物体? (What’s an object?)It is just a name that you can use to call up stored data. For example, you can save data into an object like a or b. 它只是一个名称,可用于调用存储的数据。 例如,您可以将数据保存到a或b这样的对象中。 > a <- 5
> a
[1] 5 如何在R中创建对象? (How to create an Object in R?)To create an R object, choose a name and then use the less-than symbol, <, followed by a minus sign, -, to save data into it. This combination looks like an arrow, <-. R will make an object, give it your name, and store in it whatever follows the arrow. 要创建R对象,请选择一个名称,然后使用小于号< ,后跟减号-将数据保存到其中。 这种组合看起来像箭头<- 。 R将创建一个对象,为其命名,并将其存储在箭头后面的任何位置。 When you ask R what’s in a, it tells you on the next line. For example: 当您问R中的内容时,它会在下一行告诉您。 例如: > die <- 1:6
> die
[1] 1 2 3 4 5 6You can name an object in R almost anything you want, but there are a few rules. First, a name cannot start with a number. Second, a name cannot use some special symbols, like ^, !, $, @, +, -, /, or *: 您几乎可以在R中为对象命名,但是有一些规则。 首先,名称不能以数字开头。 其次,名称不能使用某些特殊符号,例如^, !, $, @, +, -, /, or * : R also understands capitalization (or is case-sensitive), so name and Name will refer to different objects. R还了解大小写(或区分大小写),因此name和Name将引用不同的对象。 You can see which object names you have already used with the function ls(). 您可以看到函数ls()已经使用了哪些对象名称。 Learn R programming language basics in just 2 hours with this free course on statistical programming 这项免费的统计编程课程仅需2个小时即可学习R编程语言基础知识 An introduction to web scraping using R 使用R进行网页抓取的简介 An introduction to aggregates in R: a powerful tool for playing with data R中聚合的简介:强大的数据处理工具
翻译自: https://www.freecodecamp.org/news/r-programming-language-explained/
r语言是高级编程语言
R语言中用double表示日期,即从1970-1-1距离给定日期的天数,将5位数字日期转为正常日期格式的方法as.Date(16543,origin='1970-1-1')转载于:https://www.cnblogs.com/MarsMercury/p/4906269.html
您愿意向朋友推荐“博客详情页”吗?
强烈不推荐
不推荐
一般般
推荐
强烈推荐

我要回帖

更多关于 编程中double什么意思 的文章

 

随机推荐