tag:blogger.com,1999:blog-5902574258306547143.post983372239320201926..comments2024-01-18T12:48:27.027-08:00Comments on Shifting sands: Using apply, sapply, lapply in RPetehttp://www.blogger.com/profile/09556415961629445879noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-5902574258306547143.post-48533049845976798902018-02-16T16:51:02.140-08:002018-02-16T16:51:02.140-08:00Hi Joshua, I found this very helpful. I am newer t...Hi Joshua, I found this very helpful. I am newer to R and I was running into some errors with converting a data.frame to a matrix and I was receiving an error with the atomic type, so thank you!<br /><br />I also found this article helpful because I have had some confusion around the apply family and when to use each function. Thank you for the insight!Anonymoushttps://www.blogger.com/profile/13643034492391332614noreply@blogger.comtag:blogger.com,1999:blog-5902574258306547143.post-1634220230868183722017-12-11T03:11:00.687-08:002017-12-11T03:11:00.687-08:00I woulf like to see that exemple too, thanks for y...I woulf like to see that exemple too, thanks for your effortsilhamitahttps://www.blogger.com/profile/15336879647924970249noreply@blogger.comtag:blogger.com,1999:blog-5902574258306547143.post-27173996956502255702017-04-06T14:01:57.836-07:002017-04-06T14:01:57.836-07:00I would like to have the example too.Can you plz p...I would like to have the example too.Can you plz post it whenever you get a chance.ThanksKittuhttps://www.blogger.com/profile/03946578899787257382noreply@blogger.comtag:blogger.com,1999:blog-5902574258306547143.post-33873029928550740752017-01-22T06:32:50.070-08:002017-01-22T06:32:50.070-08:00Such a great post!Such a great post!Anonymoushttps://www.blogger.com/profile/07534311507766892802noreply@blogger.comtag:blogger.com,1999:blog-5902574258306547143.post-49235469103990196002016-05-07T08:31:56.365-07:002016-05-07T08:31:56.365-07:00Hi Pete,
In your second paragraph under "usi...Hi Pete,<br /><br />In your second paragraph under "using sapply and lapply" you are trying to tell us why we might want to use sapply and lapply instead of apply because we might "require traversal of our data in a less than linear way" and that we also might want to "compare the current observation with the value 5 periods before it."<br /><br />However, in your subsequent answer to this problem you raised you only give us an alternative way of doing the exact same calculation you did using the apply() method (i.e. testing the means of the three rnorm-methods). <br /><br />Could you please provide an example highlighting how the use of sapply or lapply would enable me to traverse through data in a less than linear way and allow me to compare a current observation with a value 5 periods before it in a way that the apply() cannot?<br /><br />Please note that I am still a beginner in R.<br /><br />Thanks in advance :)Anonymoushttps://www.blogger.com/profile/09516766017123631339noreply@blogger.comtag:blogger.com,1999:blog-5902574258306547143.post-49609150150187691452016-01-07T01:08:32.741-08:002016-01-07T01:08:32.741-08:00In general, instead of passing the indexes to use,...In general, instead of passing the indexes to use, I would try pass the data itself and let the internals of apply do the subsetting and make the function operate on that data, vs subsetting the data manually in the apply function we pass in. <br /><br />This isn't always possible though I know, and it is fine to pass indexes really, I am just a bit uptight about it I think.<br /><br />Thanks for you comment though and sorry for the delayed reply, I always have trouble posting comments on blogger!Petehttps://www.blogger.com/profile/09556415961629445879noreply@blogger.comtag:blogger.com,1999:blog-5902574258306547143.post-62273065561188762372015-08-01T07:56:10.814-07:002015-08-01T07:56:10.814-07:00Thank you for this insightful and practical post.
...Thank you for this insightful and practical post.<br /><br />In the 3rd to last paragraph, you mentioned that you do not recommend passing the index argument in the way you just demonstrated. So, what method would you recommend?Adrianhttps://www.blogger.com/profile/04806904322564117938noreply@blogger.comtag:blogger.com,1999:blog-5902574258306547143.post-85854641619813292182015-08-01T07:54:40.376-07:002015-08-01T07:54:40.376-07:00This comment has been removed by the author.Adrianhttps://www.blogger.com/profile/04806904322564117938noreply@blogger.comtag:blogger.com,1999:blog-5902574258306547143.post-88938697953571212102014-05-25T23:52:04.648-07:002014-05-25T23:52:04.648-07:00Great post! Thank you so much for sharing..
For ...Great post! Thank you so much for sharing.. <br /><br />For those who want to learn R Programming, here is a great new course on youtube for beginners and Data Science aspirants. The content is great and the videos are short and crisp. New ones are getting added, so I suggest to subscribe. <br />https://www.youtube.com/watch?v=BGWVASxyow8&list=PLFAYD0dt5xCzTQHDhMPZwBoaAXWeVhZzg&index=19<br />Selva Prabhakaranhttps://www.blogger.com/profile/05519694374996247829noreply@blogger.comtag:blogger.com,1999:blog-5902574258306547143.post-68412684986060319362012-12-22T19:54:27.749-08:002012-12-22T19:54:27.749-08:00Hi Joshua, thank you I was not fully aware of that...Hi Joshua, thank you I was not fully aware of that, and it has bitten me in the past as well. I have updated the post. <br /><br />Thanks for stopping by, nice to see you here!Petehttps://www.blogger.com/profile/09556415961629445879noreply@blogger.comtag:blogger.com,1999:blog-5902574258306547143.post-11057313887737909482012-12-19T04:12:48.445-08:002012-12-19T04:12:48.445-08:00You suggest using apply() on a matrix or data.fram...You suggest using apply() on a matrix or data.frame, but it's very important to note that apply() always coerces its first argument to a matrix/array. This is important because a matrix/array can only contain a single atomic type, whereas a data.frame can contain columns of varying types/classes.<br /><br />When a data.frame is converted to a matrix, it will be converted to the highest atomic type of any of the columns of the data.frame (e.g. if the data.frame has 9 numeric columns and 1 character column, it will be converted to a 10 column character matrix).Joshua Ulrichhttps://www.blogger.com/profile/16641971932645230429noreply@blogger.com