r语言中删除向量的某些元素
Vectors in R are the fundamental data types. This is because the R compiler treats all scalars (numerics, integers, etc.) and matrices as special cases of vectors.
R中的向量是基本数据类型。 这是因为R编译器将所有标量(数字,整数等)和矩阵都视为向量的特殊情况。
From a data scientist’s perspective, you can consider a vector as a collection of observations across an interval of time, such as temperatures read every day, total sales for the day, etc. R provides several relevant functions to handle vectors from this perspective.
从数据科学家的角度来看,您可以将向量视为一段时间内观察值的集合,例如每天读取的温度,一天的总销售额等。R从此角度提供了一些相关函数来处理向量。
在R中创建向量 (Creating Vectors in R)
The creation of a vector is done using the c()
function.
向量的创建是使用c()
函数完成的。
myvec <- c(3.1,45,1,2,80)
R language provides us the functionality to dynamically calculate values and assign them to vectors.
R语言为我们提供了动态计算值并将其分配给向量的功能。
> myvec2 <- c(3,5*8,(9/4))
> myvec2
[1] 3.00 40.00 2.25
We can create vectors using previously created variables.
我们可以使用先前创建的变量创建矢量。
> a <- 10
> b <-14.8
> c <-2
> myvec3 <- c(1,a,b,c)
> myvec3
[1] 1.0 10.0 14.8 2.0
We can also create a vector using two or more of the existing vectors.
我们还可以使用两个或多个现有向量创建向量。