1) Create a vector (4,6,3,4,6,3,…..,4,6,3) Where there are 10 occurrences of 4 Using repeat function
ANS=>
> v1 <- c(4,6,3,4,6,3,4,6,3)
> v1
> rep(v1,time=2)
[1] 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3
> --------------------------------------------------------------
2) Use the function paste to create the following character vectors of length 30: ("fn1", "fn2", ..., "fn30").
In this case, there is no space between fn and the number following.
ANS=>
> paste("fn",v3,sep = "_")
[1] "fn_1" "fn_2" "fn_3" "fn_4" "fn_5" "fn_6" "fn_7" "fn_8" "fn_9" "fn_10" "fn_11"
[12] "fn_12" "fn_13" "fn_14" "fn_15" "fn_16" "fn_17" "fn_18" "fn_19" "fn_20" "fn_21" "fn_22"
[23] "fn_23" "fn_24" "fn_25" "fn_26" "fn_27" "fn_28" "fn_29" "fn_30"
>
> paste(collapse ="fn",v3)
[1] "1fn2fn3fn4fn5fn6fn7fn8fn9fn10fn11fn12fn13fn14fn15fn16fn17fn18fn19fn20fn21fn22fn23fn24fn25fn26fn27fn28fn29fn30"
4) Create a character vector like "Android", "Java", "R" , "C" , "PHP" and print length of each vector element output is like 7 4 1 1 3,.
ANS=>
> v4 <- c("Android", "Java", "R" , "C" , "PHP")
> v4
> v4
[1] "Android" "Java" "R" "C" "PHP"
> nchar(v4)
[1] 7 4 1 1 3
>
ANS=>
> v1 <- c(4,6,3,4,6,3,4,6,3)
> v1
> rep(v1,time=2)
[1] 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3 4 6 3
> --------------------------------------------------------------
2) Use the function paste to create the following character vectors of length 30: ("fn1", "fn2", ..., "fn30").
In this case, there is no space between fn and the number following.
ANS=>
> paste("fn",v3,sep = "_")
[1] "fn_1" "fn_2" "fn_3" "fn_4" "fn_5" "fn_6" "fn_7" "fn_8" "fn_9" "fn_10" "fn_11"
[12] "fn_12" "fn_13" "fn_14" "fn_15" "fn_16" "fn_17" "fn_18" "fn_19" "fn_20" "fn_21" "fn_22"
[23] "fn_23" "fn_24" "fn_25" "fn_26" "fn_27" "fn_28" "fn_29" "fn_30"
>
> paste(collapse ="fn",v3)
[1] "1fn2fn3fn4fn5fn6fn7fn8fn9fn10fn11fn12fn13fn14fn15fn16fn17fn18fn19fn20fn21fn22fn23fn24fn25fn26fn27fn28fn29fn30"
4) Create a character vector like "Android", "Java", "R" , "C" , "PHP" and print length of each vector element output is like 7 4 1 1 3,.
ANS=>
> v4 <- c("Android", "Java", "R" , "C" , "PHP")
> v4
> v4
[1] "Android" "Java" "R" "C" "PHP"
> nchar(v4)
[1] 7 4 1 1 3
>
No comments:
Post a Comment