Is it possible to create new variables using R? (Newbie)

Greetings all!

I am currently working on a case study, which requires me to create new variables using R, and after much research, I cannot find a helpful answer. The case study calls for the following:

• Create a numeric variable that counts the total seasons of purchase through Spring 07.
• Create a variable that indicates whether the customer is a multichannel buyer or not
• Create a variable that indicates whether or not the customer has gift dollars or not

P.S. I am using a Microsoft Excel dataset for a multichannel company.

Any help would be greatly appreciated! Thank you all in advance!

See the FAQ: How to do a minimal reproducible example reprex for beginners. Lacking one, only abstract guidance is possible.

The source data for the first variable might look like purch below,
representing a sequence of purchases for 28 consecutive seasons, in which case,

set.seed(137)
purch <- sample(0:5,28,replace=TRUE)
length(purch) - length(purch[which(purch == 0)])
#> [1] 25

indicating that 25 of 28 seasons had non-zero sales.

The other two are identical in form—boolean vectors, with TRUE/FALSE values. Assuming there are two vectors, also of length 28, encoding multichannel status and gift dollar status, respectively through encoding of 1/0. Then

cust_attribute   <- c(1,0,0,1,1,0,0,0,1,0,1,1,1,0,0,1,0,1,1,0,0,0,1,1,1,1,0,1)
cust_attribute > 0
#>  [1]  TRUE FALSE FALSE  TRUE  TRUE FALSE FALSE FALSE  TRUE FALSE  TRUE  TRUE
#> [13]  TRUE FALSE FALSE  TRUE FALSE  TRUE  TRUE FALSE FALSE FALSE  TRUE  TRUE
#> [25]  TRUE  TRUE FALSE  TRUE

This brings to the fore the want of a reprex. Having to guess at the structure of the source data likely makes the answer less helpful than it might otherwise be.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.