Videos
i saw it in this code
dat2 <- lapply(dat, \(x) x - min(x)) |> list2DF()
I understand that it carries the last operation, but what does that mean? I am looking for a very simplified definition of it.
%>% is most commonly used as an operator for the popular dplyr package
It can be used to chain code together. It is very useful when you are performing several operations on data, and don’t want to save the output at each intermediate step.
%>% means whatever you want it to mean, in Base R anyway:
> %>%
Error: unexpected SPECIAL in "%>%"
(which means that symbol is not defined.)
Binary operators are ones that have an input from the left and from the right of the operator, just like *, + etc. You use them as you would mathematically like a * b, which R turns into the call '*'(a, b). R allows you to add your own binary operators via the %foo% syntax, with foo replace by whatever you want, as long as it hasn't already been used by R, which includes %*% and %/% for example.
`%foo%` <- function(x, y) paste("foo", x, "and foo", y)
> 1 %foo% 2
[1] "foo 1 and foo 2"
%>% takes on a specific and well-defined meaning once you load the magrittr R package for example, where it is used as a pipe operator might be in a Unix shell to chain together a series of function calls.
I have been playing a few games with my friends and during the match (wich we won) the enemy team was constantly typing the word "r" in chat. Does anyone know what this means? I'm assuming its slang for special needs but unsure.
In terms of ascii code, it's 3 -- since they're 10 and 13 respectively;-).
But seriously, there are many:
- in Unix and all Unix-like systems,
\nis the code for end-of-line,\rmeans nothing special - as a consequence, in C and most languages that somehow copy it (even remotely),
\nis the standard escape sequence for end of line (translated to/from OS-specific sequences as needed) - in old Mac systems (pre-OS X),
\rwas the code for end-of-line instead - in Windows (and many old OSs), the code for end of line is 2 characters,
\r\n, in this order - as a (surprising;-) consequence (harking back to OSs much older than Windows),
\r\nis the standard line-termination for text formats on the Internet - for electromechanical teletype-like "terminals",
\rcommands the carriage to go back leftwards until it hits the leftmost stop (a slow operation),\ncommands the roller to roll up one line (a much faster operation) -- that's the reason you always have\rbefore\n, so that the roller can move while the carriage is still going leftwards!-) Wikipedia has a more detailed explanation. - for character-mode terminals (typically emulating even-older printing ones as above), in raw mode,
\rand\nact similarly (except both in terms of the cursor, as there is no carriage or roller;-)
In practice, in the modern context of writing to a text file, you should always use \n (the underlying runtime will translate that if you're on a weird OS, e.g., Windows;-). The only reason to use \r is if you're writing to a character terminal (or more likely a "console window" emulating it) and want the next line you write to overwrite the last one you just wrote (sometimes used for goofy "ascii animation" effects of e.g. progress bars) -- this is getting pretty obsolete in a world of GUIs, though;-).
Historically a \n was used to move the carriage down, while the \r was used to move the carriage back to the left side of the page.