五月天青色头像情侣网名,国产亚洲av片在线观看18女人,黑人巨茎大战俄罗斯美女,扒下她的小内裤打屁股

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

R語言代做編程輔導(dǎo)ASSIGNMENT THREE - BASIC R SKILS(附答案)

2022-12-14 22:30 作者:拓端tecdat  | 我要投稿

全文鏈接:http://tecdat.cn/?p=30904

PROBLEM 1) Comparing Vectors

Description: Given two vectors, the longer will be deteremined and returned. In the event of a tie, the vector called x will be returned

longVec<-function(x,y) {lv=ifelse(length(x)>length(y),x,y) return(lv) }

PROBLEM 2) Intersection Subsets

Script Name: vowelMax Input: Two numeric vectors Output: One numeric vector consisting of only even numbers Error Checking: 1) If either input is empty, return NULL 2) If either vector is not numeric return NULL 3) If the vectors have an empty intersection (length of intersection is 0), return NULL 4) If there are no even numbers in the intersection return NULL>

Description: Given two vectors, find their intersection (numbers common to both) and remove all of the odd numbers and return the even numbers

Hints:
Run the command: help(intersect) For a number x, (x%%2) is zero if x is even and one if x is odd. Look into indexing a vector with logical values

commonEven<-function(x,y) {if(is.null(x) || is.null(y)) return(NULL) else{if(!is.numeric(x) || !is.numeric(y)) return(NULL) else{if(length(intersect(x,y))==0) return(NULL) else{if(min(x%%2)==1 || min(y%%2)==1) return(NULL)

PROBLEM 3) Longest first difference

Script Name: maxDiff Input: x: a numeric vector seqName: a string containing the name of the vector

Output: A nonzero number equal to the maximum absolute difference of the sequence

Error Checking:

  1. If the input is empty, return NULL

  2. If the vector is not numeric, return NULL Messages: Best described by examples. See below:

"|(a[9]-a[8])| = 7 is the maximum absolute difference"

"Input vector must be numeric."

"Sequence is empty"

Hint: Run the command: help(intersect) For a number x, (x%%2) is zero if x is even and one if x is odd. Look into indexing a vector with logical values Description: Given a sequence, {a[j]}, define the maximum absolute difference as maximum absolute difference of {a} = max |(a[j+1]-a[j])| j=1,2,3,...,n-1

---------------------------- Example: Good Case: > e<-c(5,7,10,8,4,0,2,-3,-10) > e [1] ? 5 ? 7 ?10 ? 8 ? 4 ? 0 ? 2 ?-3 -10 > maxDiff(e,"a") [1] "|(a[9]-a[8])| = 7 is the maximum absolute difference" [1] 7 Error case: Nonnumeric vector > maxDiff(c("cat","dog"),"pets") [1] "Input vector must be numeric." NULL Error case: Empty vector > x<-c(2341) > x<-x[-1] > maxDiff(x,"a") [1] "Sequence is empty" NULL End Example-------------------------------maxDiff<-function(x,seqName) {if(is.numeric(x)==FALSE)cat("Input vector must be numeric.") else{if(x[-1]==0)cat("Sequence is empty") else{ Difmax=0;for(i in 1:(length(x)-1)){for(j in (i+1):length(x)){ } } }

PROBLEM 4) Counting vowels in a list a words

Script Name: vowelMax Input: A vector of words (character strings) Output: The word with the most vowels Error Checking: If the vector of words is empty, a message is written saying "Vector of words is empty" and returning NULL

Description: Given a vector of word (character strings), this function finds and returns the word with the most vowels.

vowelMax<-function(a) {if(length(a)==0)cat("Vector of words is empty") vowmax=0for(i in 1:length(a)){ vowc=0;for(j in ?1:nchar(a[i])) { cat


R語言代做編程輔導(dǎo)ASSIGNMENT THREE - BASIC R SKILS(附答案)的評論 (共 條)

分享到微博請遵守國家法律
南雄市| 英吉沙县| 云浮市| 红安县| 定襄县| 徐州市| 金寨县| 宁波市| 巴林左旗| 河北区| 迁西县| 湾仔区| 高邑县| 清河县| 汽车| 府谷县| 泾阳县| 盐源县| 调兵山市| 巍山| 织金县| 汶上县| 北辰区| 南华县| 平度市| 稷山县| 巴青县| 奉新县| 新闻| 镇赉县| 永寿县| 确山县| 屯留县| 兴文县| 壶关县| 南昌市| 锦屏县| 靖边县| 贡嘎县| 盘锦市| 永福县|