[R] Pixel Image Reshaping using R

Paul Bernal p@u|bern@|07 @end|ng |rom gm@||@com
Thu Feb 24 19:31:09 CET 2022


Thank you Ivan. Basically, what I am being asked to do is to take the
train.csv dataset, and store it in a data structure so that the data can be
reshaped into a matrix of size 28 x 28, then I just need to print some
indices of that (e.g. index 1, 2, 4, 7,, etc.)

I basically tried the following:
dataframe_train <- array(read.csv(file_path_2, header=TRUE,
stringsAsFactors = FALSE), 28, 28)

then printing out several indices by doing (I know this could be done with
a for loop better but I tried this):

print(dataframe_train[1])
print(dataframe_train[2])
print(dataframe_train[4])
print(dataframe_train[7])
print(dataframe_train[8])
print(dataframe_train[9])
print(dataframe_train[11])
print(dataframe_train[12])
print(dataframe_train[17])
print(dataframe_train[22])

I am just unsure if I am achieving what is asked.

Best regards,
Paul


El jue, 24 feb 2022 a las 13:25, Ivan Krylov (<krylov.r00t using gmail.com>)
escribió:

> On Thu, 24 Feb 2022 13:12:16 -0500
> Paul Bernal <paulbernal07 using gmail.com> wrote:
>
> > dataframe_train <- as.matrix((read.csv(file_path_2, header=TRUE,
> > stringsAsFactors = FALSE)))
>
> Have you removed the first column containing the labels?
>
> > dim(dataframe_train) <- c(28,28)
>
> This assumes that dataframe_train is a single 784-element vector.
> Presumably, it's a whole matrix containing many such vectors as rows.
>
> > Would this do the work to reshape original dataset into a 28 x 28
> > matrix?
>
> Probably not. Use image() to plot a matrix and check. Wouldn't you want
> the original dataset to consist of many such matrices, that is, a
> three-way array?
>
> > When I print the original dataframe I get the message:
> > [ reached getOption("max.print") -- omitted 41999 rows ] this only
> > means that R will not pront the whole data, but is not trimming
> > anything right?
>
> That's right. Use str() to examine objects. Most of them (except long
> and/or deeply nested lists) should produce shorter output that's easier
> to understand.
>
> --
> Best regards,
> Ivan
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list