I am new in this board and a new user. Here is my naive question:
I have some data file which are mixed with numerical values and characters. I want only numerical values. How can I check if a value is numerical or charcter? My data is looked like
HISTORIC PRECIPITATION [IN] STATION: 897
Annual Data Display: Summary for period ending 1929/ 9/30
Day Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep
1 1.980 0.000 0.231 0.605 0.682 0.242 0.000 0.000 0.814 0.000 0.000 0.110
2 1.089 0.000 0.000 0.880 0.220 0.605 0.000 1.012 0.000 0.044 0.000 0.011
3 0.165 0.044 0.000 0.000 0.000 0.088 0.044 0.088 0.000 0.000 0.088 0.000
4 0.880 0.231 0.000 0.000 0.000 0.000 0.275 0.110 0.000 0.000 0.000 0.000
5 0.869 0.132 0.000 0.000 0.000 0.935 0.000 0.220 0.000 0.000 0.000 0.000
2 1.089 0.000 0.000 0.880 0.220 0.605 0.000 1.012 0.000 0.044 0.000 0.011
3 0.165 0.044 0.000 0.000 0.000 0.088 0.044 0.088 0.000 0.000 0.088 0.000
4 0.880 0.231 0.000 0.000 0.000 0.000 0.275 0.110 0.000 0.000 0.000 0.000
5 0.869 0.132 0.000 0.000 0.000 0.935 0.000 0.220 0.000 0.000 0.000 0.000
連結已複製
10 回應
You could read each line as a character string. If you know what the acceptable formats are, and can distinguish the strings containing numerical data, you can use internal read to process the strings containing numeric fields after identifying them.
Here is a solution that I extracted from my software. The basic procedures do some more checking (to get away from some of the things that list-directed format passes, as Steve warned about) and are more general, but this solution works well, especially if you can assert that the lines you are interested in processing have the same number of numbers in them and that they occur in the beginning of the line. I have found that this is often the case.
I attach the function, "get_dirtfile", and a driver for your example, that I have put in the "example.txt" file.
Best wishes
Lars
I attach the function, "get_dirtfile", and a driver for your example, that I have put in the "example.txt" file.
Best wishes
Lars
