当前位置: 首页> 教育> 大学 > 陵水媒体建站哪家好_制作网站软件用什么语言_百度推广关键词怎么设置好_seo优化教程

陵水媒体建站哪家好_制作网站软件用什么语言_百度推广关键词怎么设置好_seo优化教程

时间:2025/7/12 5:54:05来源:https://blog.csdn.net/weixin_43408020/article/details/146509432 浏览次数:1次
陵水媒体建站哪家好_制作网站软件用什么语言_百度推广关键词怎么设置好_seo优化教程

Foreword

Yeah!! My dear friends, we meet in the article again. Today maybe is terrible, tomorrow maybe also is terrible, but we only just understand Studying will let us out of fool, we will get progress on these things. Cheer!! My dear friends.

Vector

Exam1:

#Vector
#Use c() function to finish creation,
#it also could combine two vectors to one vector.
vector = c(1:10)
print("Vector:")
print(vector)vector2 <- sample(vector,4)
print("From vector random select 4 elements to create vector2:")
print(vector2)vectorA <- c(vector,vector2)
print("Combine Vector with Vector2:")
print(vectorA)character = paste0("day",vector2)
characterB <- paste0(vector,"day")
print("Combine the 'day' with Vector2")
print(character)
print(characterB)

Output result:
在这里插入图片描述
From the above program, we know create vector is use c() function, c(x:y) could create a from x to y integer type and the tolerance is 1 vector. Sample(x,y) could random select y elements in the x vector to create new vector【In fact, it’s previous vector subset】, c (x,y) could combine two vectors to one vector. Paste0(x,y) could combine integer type vector with character type vector, and it’s parameter x or y haven’t sequence.

Exam2:

vector3 <- c(5,4,7,6,8,9,11,9,5,11,5)
print("vector3:")
print(vector3)
element_value <- vector3[5]
print("Vector3[5]:")
print(element_value)position = which(vector3 == 5)
print("Find all Element value <- 5 position:")
print(position)max_value <- which.max(vector3)
print("Find the vector max value position:")
print(max_value)
min_value <- which.min(vector3)
print("Find the vector min value position:")
print(min_value)

Output result:
在这里插入图片描述
Through the program, we know the vector element position is from 1 start to end over【it isn’t from 0 to start.】. Vector[x], x is element position, it could gain the position corres-ponding element, which(x), x is condition, it could seek all meet the condition element values. which.max(x), x is vector, could seek maximum value position in the vector, which.min(x), x is vector, could seek minimum value position in the vector.

Exam3:

vector4 <- c(1:5)
vector5 <- c(seq.int(2,10))
vector6 <- paste0("notebook",vector4)
vector7 <- c("Scala","C","Java","Python")
print("Vector4:")
print(vector4)
print("Vector5:")
print(vector5)
set1 = intersect(vector4,vector5)
print("Set_intersect:")
print(set1)
print("Vector6:")
print(vector6)
print("Vector7:")
print(vector7)
set2 = union(vector6,vector7)
print("Set_union:")
print(set2)

Output result:
在这里插入图片描述
From the program, we know seq() could create tolerance is 1 sequence, intersect(x,y) could calculate x vector and y vector intersect set. paste0(x,y) could combine x vector with y vector, union(x,y) could calculate x vector and y vector union set.

Exam4:

vector8 <- c(1:10)
print("Vector8:")
print(vector8)
print("Length:")
vector_len <- length(vector8)
print(vector_len)
print("Max_value:")
max_value = max(vector8)
print(max_value)
print("Min_value")
min_value = min(vector8)
print(min_value)
print("Mean_value:")
mean_value <- mean(vector8)
print(mean_value)
print("median_value:")
median_value = median(vector8)
print(median_value)
vector9 <- c(1,3,4,1,2,5,3,7,6)
print("vector9:")
print(vector9)
Sort_vector = sort(vector9)
print("Sort_vector:")
print(Sort_vector)

Output result:
在这里插入图片描述
From above program, we know length(x), x is vector, it could gain the vector length, max(x), x is vector, it could gain maximum value in the vector, min(x), x is vector, it could gain minimum value in the vector. mean(x), x is vector, it could gain mean value in the vector, median(x), x is vector, it could gain median value in the vector. Sort(x), x is vector, it could sort the vector.

Exam5:

vector10 <- c(1:10)
Letter_vector = letters[vector10]
print("Vector10:")
print(vector10)
print("Letters_vector:")
print(Letter_vector)match_position <- match(Letter_vector,letters[vector10])
print("Match translate vector11 to Letters position:")
print(match_position)

Output result:
在这里插入图片描述
Through the program ,we know letters(x), x is vector, it could translate vector integer type elements to letters. Match(x,y), x and y both is vector, it will from x vector find y vector elements, it like y vector is x vector subset, the function will return x position corresponding y element.

Exam6:

Number = sample(0:100,10,replace=T)
print("Number:")
print(Number)
labels = c("差","中","良","优")
print("labels:")
print(labels)
num <- cut(Number,breaks = c(0,60,80,90,100),labels= labels)
print("Num:")
print(num)

Output result:
在这里插入图片描述
From the above program, we know sample(x,y,replace=T), x is vector, y is random select element numbers, replace=T express both apply in the x vector. Cut(x,breaks=y,labels=z),
x is vector, y also is vector, but y is region, the region is used to divide x vector data, among the y vector elements are used labels z vector judge the x vector data attribute.

Exam7:

vectorX <- sample(9,6)
print("VectorX:")
print(vectorX)
SortX <- sort(vectorX)
print("Sort the vectorX:")
print(SortX)Order_X <- order(vectorX)
print("Gain the order position corresponding number:")
print(Order_X)
result = vectorX[Order_X]
print("The position corresponding vector value:")
print(result)

Output result:
在这里插入图片描述
Through the above Codes, we know sample(x,y), x is the vector maximum value, y is the vector length, it could create a length is 6 and maximum value is 9 vector. Sort(x), x is vector, it could sort the vector. Order(x), x is vector, it could gain the order position corresponding number value, vectorX[x], x is vector, it will from x vector element select value to ouput corresponding vectorX element position number value.

Exam8:

char1 <- c("I like R!!!")
print("char1:")
print(char1)
char1_length <- nchar(char1)
print("The character length is:")
print(char1_length)
child_char <- substr(char1,1,9)
print("Extract the character in char1:")
print(child_char)

Output result:
在这里插入图片描述
From the above Codes, we know c() function also could create character vector. nchar(x), x is character type vector, it could gain the character vector length, substr(x,y,z), x is character type vector, y is begin position, z is over position, it could extract a new character type vector from 1 to 9 position elements in the x vector.

Exam9:

char2 <- c("Java","Scala","Python","C","R","C++","Julia","Pascal")
char2_result <- paste("Char2:",char2)
print(char2_result)
link_char2 <- paste(char2,collapse = ",")char2_change <- paste(c("Combine the Char2:"),link_char2)
print(char2_change)char3 <- c("R")
Num3 <- c(3:6)
combine_char = paste(char3,Num3)
print("Combine char and number:")
print(combine_char)
print(class(combine_char))

Output result:
在这里插入图片描述
Through the above Codes, we know paste(x,y), x and y both is vector, if y is single character combined vector, x vector will mapper each character element in y vector, else if y is a string, x will combine y to create a new string. paste(x,y) also could combine integer type vector with character type vector to create a new character vector.

Exam10:

content <- c("I like Java",'C',"Scala","Python",'R')
print("Content:")
print(content)
char_position <- grep(c("Scala"),content)
print("Scala position:")
print(char_position)
replace_char <- gsub(c("like"),c("love"),content)
print("like replace to love:")
print(replace_char)

Output result:
在这里插入图片描述
From the above Codes, we know grep(x,y), x is vector, y also is vector, it will seek x vector in y vector and output x vector element corresponding position at the y vector. gsub(x,y,z), x ,y and z both is vector, it could replace x to y in the z vector.

Exam11:

salary <- c("3万","5万","7万","6万","2万")
print("Salary:")
print(salary)
salary2 <- gsub('万',"0000",salary)
print("Salary translate:")
print(salary2)
Type <- class(salary2)
salary_type = paste("The Salary Type is",Type)
print(salary_type)
salary3 = sort(salary2)
print(salary3)
print("Salary translate to number:")salary_num <- as.numeric(salary2)
print(salary_num)
salary_class <- class(salary_num)
Type <- paste("The Translate Salary Type is",salary_class)
print(Type)
Sort_num <- sort(salary_num)
print("Sort the Salary:")
print(Sort_num)

Output result:
在这里插入图片描述
Through the above Codes, we know gsub(x,y,z), x replace to y in z vector. The result also is character vector and the character could use sort(x) to sort character vector, as.numeric(x), x is vector, it could translate character type vector to integer type vector, then we could use sort(x) to sort the vector, x is integer type vector.

In the end

I gratitude for your watch my articles, maybe my passages have some mistakes, I hope you could point them, please you insist to learn R, R isn’t simple for Beginer, but you still continue to study is cool! Remember!! give up or give in is so easy. Cheer!! my dear friends, your Pan【one man of the common persons】.

关键字:陵水媒体建站哪家好_制作网站软件用什么语言_百度推广关键词怎么设置好_seo优化教程

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: