Learn R Programming

do (version 2.0.0.1)

Apriori.Basket: Convert vector to sparse matrix

Description

Convert vector or dataframe to sparse matrix.

Usage

Apriori.Basket(x, sep = ";", dup.delete = FALSE)

Value

a sparse matrix

Arguments

x

a vector

sep

one separator

dup.delete

whether to delete duplicated values in the same row, default is FALSE

Examples

Run this code
# convert a vector to sparse matrix
g=c('a,b,a,,','a,b,c,d','d,c,f,g,h')
Apriori.Basket(x=g,sep = ',')

# convert a dataframe to sparse matrix
library(data.table)
df=fread(text = '
t1 t2 t3
a NA d
g a j')
Apriori.Basket(x=df,sep = ',')

Run the code above in your browser using DataLab