Note about data frames in json

This commit is contained in:
hadley 2015-12-01 03:31:06 +04:00
parent f9d61f5171
commit f26fdd729f
1 changed files with 8 additions and 1 deletions

View File

@ -158,7 +158,7 @@ embed_jpg("images/pepper-3.jpg", 300)
## A common pattern of for loops
Lets start by creating a stereotypical list: an eight element list where each element contains a random vector of random length. (You'll learn `rerun()` later.)
Lets start by creating a stereotypical list: an eight element list where each element contains a random vector of random length. (You'll learn about `rerun()` later.)
```{r}
x <- rerun(8, runif(sample(5, 1)))
@ -522,6 +522,13 @@ You'll see an example of this in the next section, as `transpose()` is particula
It's called transpose by analogy to matrices. When you subset a transposed matrix, you switch indices: `x[i, j]` is the same as `t(x)[j, i]`. It's the same idea when transposing a list, but the subsetting looks a little different: `x[[i]][[j]]` is equivalent to `transpose(x)[[j]][[i]]`. Similarly, a transpose is its own inverse so `transpose(transpose(x))` is equal to `x`.
Tranpose is also useful when working with JSON apis. Many JSON APIs represent data frames in a row-based format, rather than R's column-based format. `transpose()` makes it easy to switch between the two:
```{r}
df <- dplyr::data_frame(x = 1:3, y = c("a", "b", "c"))
df %>% transpose() %>% str()
```
### Exercises
## Dealing with failure