0

I'm building a naive Bayes classifier in R, a language I am not familiar with.

I've got multiple csv files for testing the trained classifier, which become data frames when read into R. There are 20 possible categories a given document can be classified into, and each test file contains many documents, so I need an array of 20 copies of a test file to calculate the probabilities for the 20 categories and choose the best one for each document in that test file.

So once I've read a csv file into R and have a data frame, how do I create an array or list with 20 copies of this data frame?

Servbot
  • 1
  • 3

1 Answers1

2
df <- read.csv(text='a,b\n1,a\n2,b\n3,c\n');
df;
##   a b
## 1 1 a
## 2 2 b
## 3 3 c
rep(list(df),20);
## [[1]]
##   a b
## 1 1 a
## 2 2 b
## 3 3 c
##
## [[2]]
##   a b
## 1 1 a
## 2 2 b
## 3 3 c
##
## ... (snip) ...
##
## [[19]]
##   a b
## 1 1 a
## 2 2 b
## 3 3 c
##
## [[20]]
##   a b
## 1 1 a
## 2 2 b
## 3 3 c
bgoldst
  • 34,190
  • 6
  • 38
  • 64