-
-
Save seankross/912fe3b9f19a91b0a7bd to your computer and use it in GitHub Desktop.
"%p%" <- function(left, right){ | |
paste(left, right) | |
} |
boring_function <- function(x) { | |
x | |
} |
evaluate <- function(func, dat){ | |
func(dat) | |
} |
mad_libs <- function(...){ | |
# Do your argument unpacking here! | |
args <- list(...) | |
place <- args[["place"]] | |
adjective <- args[["adjective"]] | |
noun <- args[["noun"]] | |
# Don't modify any code below this comment. | |
# Notice the variables you'll need to create in order for the code below to | |
# be functional! | |
paste("News from", place, "today where", adjective, "students took to the streets in protest of the new", noun, "being installed on campus.") | |
} |
my_mean <- function(my_vector) { | |
sum(my_vector)/length(my_vector) | |
} |
remainder <- function(num, divisor = 2) { | |
num %% divisor | |
} |
telegram <- function(...){ | |
paste("START", ..., "STOP") | |
} |
why does the telegram function not work when I'm copying exactly what others are posting, which is the same as what's posted in the discussion forums, and I've double checked what directory R is working with, and just incase, saved the script in several folders. I feel like an idiot writing down exactly what people have written above. But, I assure you it's the exact same code, lol.
Any ideas?
I had problems with the fun dat task and it finally worked when I made a hybrid code out of two peoples solutions!? I couldn't follow my own code after that but it worked...
**> > have resolved this problem. The correct code for evaluate function is:
evaluate <- function(func, dat) {
func(dat)
}
all you have to do is to clear the environment variables before submit().
Just execute the command rm(list=ls()) and then save the above code of evaluate function and then write submit(). It will work.Thanks a lot !**
THANKS!!!!!
rm(list=ls())
This is working
**> > have resolved this problem. The correct code for evaluate function is:
evaluate <- function(func, dat) {
func(dat)
}
all you have to do is to clear the environment variables before submit().
Just execute the command rm(list=ls()) and then save the above code of evaluate function and then write submit(). It will work.Thanks a lot !**
THANKS!!!!!
Thanks a lot!
I have resolved this problem. The correct code for evaluate function is:
evaluate <- function(func, dat) {
func(dat)
}all you have to do is to clear the environment variables before submit().
Just execute the command rm(list=ls()) and then save the above code of evaluate function and then write submit(). It will work.
This works!
Thanks a lot!
I have resolved this problem. The correct code for evaluate function is:
evaluate <- function(func, dat) {
func(dat)
}all you have to do is to clear the environment variables before submit().
Just execute the command rm(list=ls()) and then save the above code of evaluate function and then write submit(). It will work.
thank you it worked for me
### please help. I stuck at my_mean function
my_mean <- function(my_vector) {
x <- sum(my_vector)/length(my_vector)
x
}
submit()
| Sourcing your script...
| You're close...I can feel it! Try it again.
| Use the sum() function to find the sum of all the numbers
| in the vector. Use the length() function to find the size
| of the vector
I submitted mad_libs and it seemed to be ok, I entered the function and arguments in the console but the variables were not returned as part of the sentence, just blanks. still said I was on a roll which was very encouraging
Try this:
mad_libs(place = "place name", adjective = "lots of", noun = "somthing")
it will work.
Because the ... does not give them an order, so we should call their names when we convert the vector
remainder <- function(num, divisor = 2) {
num %% divisor
}
[save]
submit()
| Sourcing your script...
| Nice try, but that's not exactly what I was hoping for. Try again.
| Remember to set the appropriate default values!
Hello, need help with the below. Thanks.
| Now try using evaluate() along with an anonymous function to return the last element
| of the vector c(8, 4, 0). Your anonymous function should only take one argument
| which should be a variable x
.
evaluate(function(x) {x[3]}, c(8, 4, 0))
[1] 0
| You almost had it, but not quite. Try again. Or, type info() for more options.
| You may need to recall how to index vector elements. Remember that your anonymous
| function should only have one argument, and that argument should be named x
. Using
| the length() function in your anonymous function may help you.
remainder <- function(num, divisor = 2) {
num %% divisor
}
[save]
submit()| Sourcing your script...
| Nice try, but that's not exactly what I was hoping for. Try again.
| Remember to set the appropriate default values!
This worked with me:
remainder <- function(num,divisor = 2) { num %% divisor}
submit()
| Sourcing your script...
| You're the best!
Hello, need help with the below. Thanks.
| Now try using evaluate() along with an anonymous function to return the last element
| of the vector c(8, 4, 0). Your anonymous function should only take one argument
| which should be a variablex
.evaluate(function(x) {x[3]}, c(8, 4, 0))
[1] 0| You almost had it, but not quite. Try again. Or, type info() for more options.
| You may need to recall how to index vector elements. Remember that your anonymous
| function should only have one argument, and that argument should be namedx
. Using
| the length() function in your anonymous function may help you.
The answer should be:
evaluate(function(x){x[length(x)]}, c(8,4,0))
[1] 0
Hello, need help with the below. Thanks.
| Now try using evaluate() along with an anonymous function to return the last element
| of the vector c(8, 4, 0). Your anonymous function should only take one argument
| which should be a variablex
.evaluate(function(x) {x[3]}, c(8, 4, 0))
[1] 0| You almost had it, but not quite. Try again. Or, type info() for more options.
| You may need to recall how to index vector elements. Remember that your anonymous
| function should only have one argument, and that argument should be namedx
. Using
| the length() function in your anonymous function may help you.The answer should be:
evaluate(function(x){x[length(x)]}, c(8,4,0))
[1] 0
Thank you! It worked!
Would you mind breaking it down for me? The part I am having problem understanding is that the length of c(8,4,0) is 3 but yet the result of the code is "0". Why? Thanks.
Now edit and save the R script bin_op.R.
Write your own binary operator below from absolute scratch! Your binary
operator must be called %p% so that the expression:
"Good" %p% "job!"
will evaluate to: "Good job!"
"%p%" <- function(){ # Remember to add arguments!
paste(left, right, sep = " ")
Sourcing your script...
| Not exactly. Give it another go.
| Remember: 'Hello' %p% 'student!' is how you use the binary operator.
Please help me I have tried everything
i have tried with reinstalling swirl package,
tried all the help extended by you people.
still unable to resolve the issue with anoynomus functions after evaluate function
evaluate(function(x){x+1},6)
can any one tell step by step to dos
I have resolved this problem. The correct code for evaluate function is:
evaluate <- function(func, dat) {
func(dat)
}
all you have to do is to clear the environment variables before submit().
Just execute the command rm(list=ls()) and then save the above code of evaluate function and then write submit(). It will work.thank you it worked for me
struck at next step of this
Would you mind breaking it down for me? The part I am having problem understanding is that the length of c(8,4,0) is 3 but yet the result of the code is "0". Why? Thanks.
Got stuck in this same spot since it wouldn't take "evaluate(function(x){x[length(c(8,4,0))]},c(8,4,0))" even though that seems to me to fulfil all stated requirements (although admittedly it is inelegant). The reason the function returns "0" is because while the length function determines that the vector consists of three elements, the x[stuff] piece specifies that what is returned from the vector is the item in the position identified by the value within the brackets - in this case, the 3rd value. The function of the brackets is to return a subset.
What I still don't understand is how it knows that the length of "function(x){x[length(x)]}" is 3. I thought "x" referred to the function as an unpopulated equation and that the dat element provided - the vector - was a separate element from the function designated by x. I guess once the vector is plugged in, it is part of the function, but at the point the length is taken, the data element has not yet been reached.
...just a counter-intuitive order of operations, I guess. Here I am stuck in that old Excel way of thinking...
Now edit and save the R script bin_op.R.
Write your own binary operator below from absolute scratch! Your binary
operator must be called %p% so that the expression:
"Good" %p% "job!"
will evaluate to: "Good job!"
"%p%" <- function(){ # Remember to add arguments! paste(left, right, sep = " ") Sourcing your script...
| Not exactly. Give it another go.
| Remember: 'Hello' %p% 'student!' is how you use the binary operator. Please help me I have tried everything
This worked
"%p%" <- function(left,right){ # Remember to add arguments!
paste(left,right,sep=" ")
}
u save before hitting submit (
I am having the same issue and I have saved my script - any other solutions?
Copy the code you received at the end of the swirl lesson and paste it into the corresponding question below.
What is the answer??
Its for quiz after week 1
I submited the swrl exercises but what code is the LAST code??
Guys chill.
here 'func' is itself a R function, sd, mean, median all that jazz. lol. You dont need to program it, its already ingrained in R.
After making the function, try
evaluate(sd, c(1.4, 3.6, 7.9, 8.8))
it runs just fine. I was like since when does swirl have a bug lmao. 🤣Some of the comments here are F$%^ing lit.
🐉