0

I have a pgm file that can be read by r as a vector but using r code I need to convert it to a square tsv file to be read

#Import banana01 csv
banana <- read.csv("40328715_banana_01.csv", byrow=TRUE, nrow=45, ",")

banana_matrix <- matrix(c(banana), nrow = 45, ncol = 45)
banana_matrix
zephryl
  • 14,633
  • 3
  • 11
  • 30
Aoife
  • 1
  • 1
  • 1
    It is not clear what your particular problem is. Is it (a) reading the pgm or csv file, (b) changing it into a matrix, or (c) saving it as a tsv file? – Henry Feb 14 '23 at 13:41
  • it's unclear what you need to do and what you've already tried. The base approach would be `write.table()` with `sep= "\t"`. Tidy version would be `write_tsv()`. – Paul Stafford Allen Feb 14 '23 at 14:03
  • Welcome to SO, Aoife! Please realize that we don't have your csv file and have no idea what it looks like, so most suggests are speculation. It would help to provide either the first few lines of raw text from the csv file or the output from `dput(head(banana))` after reading it in. It would also help to know exactly how you expect the format to look afterwards (on the R console and/or in the resulting file). Please see https://stackoverflow.com/q/5963269, [mcve], and https://stackoverflow.com/tags/r/info for discussions on _reproducibility_. – r2evans Feb 14 '23 at 14:39
  • I have used this code to read the pgm allFiles <- list.files(path = "faces_subset", pattern = ".pgm", full.names = T) pictures <- lapply(allFiles, FUN = function(f) read.pnm(f)) my issue is connecting it to a square tsv file – Aoife Feb 14 '23 at 17:14

0 Answers0