0
$\begingroup$

I have text file with a list of numbers separated by commas, which I would like import into a notebook to be called when the name ratevector is used. If I cut and paste the numbers manually everything works fine and the length of ratevector matches the number of entries in the text file.

In[1]:= ratevector = {0.6951, 0, 0.6951, 1.4425, 0, 0, 1.5222, 0.6951, 4.3295, 4.3283}
Out[1]= {0.6951, 0, 0.6951, 1.4425, 0, 0, 1.5222, 0.6951, 4.3295,4.3283}
In[2]:= Length[ratevector]
Out[2]= 10

However when I import the data from the text file directly using the ReadList or ReadString or Import commands ratevector prints the correct values to the screen but the list is of length 1.

In[3]:= ratevector2 =Import["~/ratevector_testfile.txt"]
Out[3]= {.6951, 0, 0.6951, 1.4425, 0, 0, 1.5222, 0.6951, 4.3295, 4.3283}
In[4]:= Length[ratevector2]
Out[4]= 1

How can I import my data so that the 9 values are recognized? Here is a link to the file I'm trying to import, https://github.com/PrincessG/SignalNoise/blob/master/ratevector_testfile.txt. I also tried importing the file as a .CSV file. Thanks for any help you can give!

In[1376]:= testimport = Import["~/ratevectorfilename_.csv", "CSV"]
Out[1376]= {{0.6951, "  0.6951", "  1.4425", "  0", "   0", "   1.5222", "  0.6951", "  4.3295", "  4.3283"}}
In[1377]:= Length[testimport]
Out[1377]= 1
$\endgroup$
1
  • $\begingroup$ Welcome to Mathematica.SE! I suggest that: 1) You take the introductory Tour now! 2) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! 3) As you receive help, try to give it too, by answering questions in your area of expertise. $\endgroup$
    – bbgodfrey
    Commented Mar 9, 2015 at 3:47

1 Answer 1

0
$\begingroup$

In your last input the import is ok and the length is 1 because you have list of depth 2

To get what you want try this:

testimport = Import["~/ratevectorfilename_.csv", "CSV"][[1]]
$\endgroup$
2
  • $\begingroup$ Thank you that helped! Is there a command I can use to investigate the dimensions of my data file? Something like the str() command in R? $\endgroup$
    – PGilbert
    Commented Mar 9, 2015 at 5:04
  • $\begingroup$ yes you can use Dimensions (reference.wolfram.com/language/ref/Dimensions.html) $\endgroup$ Commented Mar 9, 2015 at 5:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.