aboutsummaryrefslogtreecommitdiff
path: root/challenge-040
diff options
context:
space:
mode:
authorMohammad S Anwar <Mohammad.Anwar@yahoo.com>2019-12-29 21:26:02 +0000
committerGitHub <noreply@github.com>2019-12-29 21:26:02 +0000
commitb76273361becaf42dbcbc25a0a96d36a60ed6361 (patch)
tree0e16dadc7dbf1db5ec056ec0bf388bd8c0aa7419 /challenge-040
parentcd30a0b791d1b9e1afef5fe96ac6c494048d247b (diff)
parent2ee588dad3c8863f75ab32bcde28bd8d50eb9fd4 (diff)
downloadperlweeklychallenge-club-b76273361becaf42dbcbc25a0a96d36a60ed6361.tar.gz
perlweeklychallenge-club-b76273361becaf42dbcbc25a0a96d36a60ed6361.tar.bz2
perlweeklychallenge-club-b76273361becaf42dbcbc25a0a96d36a60ed6361.zip
Merge pull request #1080 from wanderdoc/master
Just tried the same in R.
Diffstat (limited to 'challenge-040')
-rw-r--r--challenge-040/wanderdoc/R/ch-1.R20
-rw-r--r--challenge-040/wanderdoc/R/ch-2.R20
2 files changed, 40 insertions, 0 deletions
diff --git a/challenge-040/wanderdoc/R/ch-1.R b/challenge-040/wanderdoc/R/ch-1.R
new file mode 100644
index 0000000000..dc13f7537a
--- /dev/null
+++ b/challenge-040/wanderdoc/R/ch-1.R
@@ -0,0 +1,20 @@
+# TASK #1
+# Show multiple arrays content.
+# You are given two or more arrays. Write a script to display values of each list at a given index.
+
+# Help function qw:
+# https://stackoverflow.com/questions/520810/does-r-have-quote-like-operators-like-perls-qw
+qw <- function(x) unlist(strsplit(x, "[[:space:]]+")) # flodel in this thread.
+
+as1<-qw("I L O V E Y O U")
+as2<-qw("2 4 0 3 2 0 1 9")
+as3<-qw("! ? £ $ % ^ & *")
+
+
+dfs<-rbind(as1, as2, as3)
+
+
+for (col in 1:ncol(dfs))
+{
+ cat(dfs[,col], "\n")
+}
diff --git a/challenge-040/wanderdoc/R/ch-2.R b/challenge-040/wanderdoc/R/ch-2.R
new file mode 100644
index 0000000000..f4520d298f
--- /dev/null
+++ b/challenge-040/wanderdoc/R/ch-2.R
@@ -0,0 +1,20 @@
+# TASK #2
+# Sort SubList
+# You are given a list of numbers and set of indices belong to the list. Write a script to sort the values belongs to the indices.
+#
+# For example,
+# List: [ 10, 4, 1, 8, 12, 3 ]
+# Indices: 0,2,5
+#
+# We would sort the values at indices 0, 2 and 5 i.e. 10, 1 and 3.
+#
+# Final List would look like below:
+# List: [ 1, 4, 3, 8, 12, 10 ]
+
+arr <- c(10, 4, 1, 8, 12, 3)
+idx <- c(0, 2, 5)
+idx <- idx + 1 # While this is R.
+arr_sorted <- arr
+arr_sorted[idx] <- sort(arr_sorted[idx]) # Choroba in his blog!
+arr
+arr_sorted \ No newline at end of file