AlexWithYou
AlexWithYou

Reputation: 429

What is this error when I using Pipe in R

df2$Neighborhood %>% length()
df2$category %>% length()
table(df2$Neigborhood) %>% [order()]

This is the code I write to learn how to use the pipe. I'm not familiar with how to use it yet. An error occurred and I don't know how to fix it.

    [1] 481376
    [1] 481376
     Unknown or uninitialised column: 'Neigborhood'.integer(0)

The first two lines are able to generate a result. But not the third one. It means the neighborhood column is available. However, there are some mistakes in it. My purpose was to sort the table using function d2[order(d2)]. How can I fix it?

Upvotes: 2

Views: 75

Answers (1)

akrun
akrun

Reputation: 887501

The issue is that there is 'h' missing in 'Neigborhood'. If we use the correct column name i.e. Neighborhood, it should work if we also specify the data i.e. . from the lhs of %>%

library(magrittr)
table(df2$Neighborhood) %>% 
      .[order(.)]

It may be also better to wrap with {} if there are multiple things involved

table(df2$Neighborhood) %>%
             {.[order(.)]}

Here the . represents the data from the lhs of %>%

Upvotes: 1

Related Questions