1
$\begingroup$

I am importing simple 0s and 1s array from Excel

myDep = Import[ FileNameJoin[{NotebookDirectory[], "dependencies.xlsx"}], {"Sheets", "Data"}] 

All good

{{1., 0., 0., 1., 0., 0.}, {0., 1., 0., 0., 1., 0.}, {0., 0., 0., 1., 0., 0.}, {0., 0., 1., 1., 1., 0.}, {1., 0., 1., 0., 0., 1.}, {0., 0., 0., 1., 0., 0.}} 

But I get it imported as Real, and being a newbie I cannot find the way to import is as Integer. Any simple way to import it as Integer numbers? Sorry for such a mundane question.

Thanks a million in advance!

$\endgroup$
1
  • $\begingroup$ You may be interested in Rationalize $\endgroup$ Commented Mar 13, 2019 at 0:55

1 Answer 1

4
$\begingroup$

Konstantin, Welcome to MSE. If the data values are either 0 or 1, you can use IntegerPart to convert after importing.

IntegerPart[{{1., 0., 0., 1., 0., 0.}, {0., 1., 0., 0., 1., 0.}, {0., 0., 0., 1., 0., 0.}, {0., 0., 1., 1., 1., 0.}, {1., 0., 1., 0., 0., 1.}, {0., 0., 0., 1., 0., 0.}}] (* {{1, 0, 0, 1, 0, 0}, {0, 1, 0, 0, 1, 0}, {0, 0, 0, 1, 0, 0}, {0, 0, 1, 1, 1, 0}, {1, 0, 1, 0, 0, 1}, {0, 0, 0, 1, 0, 0}} *) 
$\endgroup$
2
  • $\begingroup$ It worked perfectly for me myDep = IntegerPart[ Import[FileNameJoin[{NotebookDirectory[], "dependencies.xlsx"}], {"Sheets", "Data"}]] $\endgroup$ Commented Mar 13, 2019 at 20:48
  • $\begingroup$ That's great. Would you mind accepting my answer. $\endgroup$ Commented Mar 13, 2019 at 23:21

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.