-2

I have a grocery sales data which has 11 columns like store name,item name,price etc. For my analysis i do not require all the column values. I need only few column values for generating a report.

what is the R code for this?

Example: Below are the column names of an sales data. i need only 6 of the below column values. I tried that coding, but error is shown, also those answers I don't understand

STORE_NAME  STORE_ID    DEVICE_SERIAL_NUMBER    BILL_NUMBER BARCODE ITEM_NAME   VARIANT_NAME    BASEPACK    CATEGORY    BRAND   MANUFACTURER    QUANTITY_SOLD   PRICE   PURCHASE_PRICE  SELLING_PRICE   SALES_VAT   USER_NAME   COUNTER CUSTOMER_NAME   CUSTOMER_PHONE  BILL_DATE   CREATED_DATE
zx8754
  • 52,746
  • 12
  • 114
  • 209
  • 2
    Check out [how to write a reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). :) – Therkel Nov 08 '17 at 09:44

1 Answers1

0

Read all the data with read.table or read.csv and then extract only those, that you can use. That's what we use square brackets for in R. You can do it either by column number or column name:

lots.of.cols <- data.frame(a=1:20, b=2:21, c=3:22, d=runif(20), e=runif(20))

only.first.two.cols <- lots.of.cols[,c(1,2)] #extract only column 1 and 2
str(only.first.two.rows)

only.a.and.b <- lots.of.cols[,c("a", "b")]
str(only.a.and.b)
Bernhard
  • 4,272
  • 1
  • 13
  • 23
  • Thanks bernad....its working....also i tried a different code like the below >tablename$STORE_NAME = NULL – rajesh Kumaar Nov 08 '17 at 10:04
  • There are endless ways to achieve this - square brackets are maybe the most versatile tool to have in your toolbox. If this was the right answer, please consider to hit the "accept this answer" button. – Bernhard Nov 08 '17 at 10:49