-5

I am beginner in R. I am looking to gathering some columns for plotting. I got this error "Error: Must supply a symbol or a string as argument". I would be happy if you help me in how to fix this error.

library(readxl)

df =read_excel("a1-cereals.xls")

# Select columns 
df%>% select (c(-1,-2,-11,-14,15))->df1

# Filtering rows 

df_Type_C <- filter (df1, Type == "C")

head (df_Type_C)

df_Type_H <- filter (df1, Type == "H")

head (df_Type_C)

#Gathering columns to make a long table 

df_long <- gather (df1,Mes_Type,2:11)

This is a sample of the dataset I am working on:

enter image description here

starja
  • 9,887
  • 1
  • 13
  • 28
Elwakdy
  • 41
  • 1
  • 1
  • 6
  • Please provide your example data by using `dput`, not as an image. See [how to make MREs](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – starja Sep 20 '20 at 08:24
  • Thank you so much for your interest. I solved the problem right now df_long <- gather(df1, key = "Element", value = "value", 2:11) – Elwakdy Sep 20 '20 at 08:26
  • ok, i will do for my next questions – Elwakdy Sep 20 '20 at 08:26
  • In general, it's bad style to separate the brackets from the function names, try to keep it together – starja Sep 20 '20 at 08:28

1 Answers1

0

This happens because gather requires a name and value argument (supplied as strings, hence the error message. I imagine that supplying this would solve your problem. However, I strong encourage you to change from gather to the pivot arguments as gather has been retired. I think your code would work fine with pivot. Please see links below and good luck!

Link1 Link2

Magnus Nordmo
  • 923
  • 7
  • 10