0

For the following ways of reading a csv file using R

cd1<-as.character(as.matrix(read.csv('traindata.csv',skip=2,nrows = 1,head=F)))

Is this the only way to read a specific row? Moreover, why we have to call as.matrix first before calling as.characte?

Phil
  • 7,287
  • 3
  • 36
  • 66
user288609
  • 12,465
  • 26
  • 85
  • 127
  • Does this answer your question? [Read csv from specific row](https://stackoverflow.com/questions/6592219/read-csv-from-specific-row) – big parma Mar 04 '21 at 17:10
  • Thanks, for my second question on as.character(as.matrix, why do we need as.matrix first? – user288609 Mar 04 '21 at 17:28
  • Hard to say with seeing the data, but you generally don't want to convert a row of a dataframe into a character vector because the columns of the data frame may contain different object types (for example, character and numeric). – big parma Mar 04 '21 at 17:37
  • @bbspring,thanks, so as.matrix works to unify the object type, is my understanding right? – user288609 Mar 04 '21 at 19:52

0 Answers0