Skip to content

not complete character in csv file

7 messages · Jean V Adams, David Winsemius, threshold +2 more

#
Dear R users, I got the following problem. Given that
[1] "010252"

Code:
intro <- data.frame()
intro[1,1] <- as.character(data[3,2])
write.csv(intro, file='intro.csv')

In 'intro.csv' file I am loosing the 0 in frot of 10252, which I need. Is
there a way to keep the full character saved? R 2.13.2 (64 bit).

Thanks, robert



--
View this message in context: http://r.789695.n4.nabble.com/not-complete-character-in-csv-file-tp4185785p4185785.html
Sent from the R help mailing list archive at Nabble.com.
#
On Dec 12, 2011, at 7:23 AM, threshold wrote:

            
Let me guess. The way you are looking at the output is with Excel and  
you are bothered by the fact that Excel will drop leading zeros from  
items it can interpret as numbers.

If you  use Excel as a viewer, you get what Excel thinks you should  
get. My attempt to format the range where the data will be loaded as  
"Text", and then load from the CSV file, failed to preserve the  
leading "0" using Excel 2011 (for Mac). That strategy used to work for  
me in prior versions of Excel at least for preventinting from  
converting text to dates, but the MS people seem to have decided to be  
even more "helpful".
#
Indeed in txt it looks fine. Anyway, I must stay without 0 because csv is THE
format.

I got another question. why for 
Table <- matrix(0,8,3)
day = "Monday"
Table[1,1]=day

all other elements become characters too?

Thanks, robert


--
View this message in context: http://r.789695.n4.nabble.com/not-complete-character-in-csv-file-tp4185785p4186427.html
Sent from the R help mailing list archive at Nabble.com.
#
Matrix (which is secretly a vector) can only have one mode
(numeric/factor/character/etc.) for all its elements. If you need
multiple types, go to a data frame

Michael
On Mon, Dec 12, 2011 at 10:39 AM, threshold <r.kozarski at gmail.com> wrote:
#
On 13/12/11 04:39, threshold wrote:
It may well be the case that csv is THE format, but csv is not the problem.
Excel is the problem.

The solution is:  Don't use Excel!!!  (This is excellent advice in any  
case.)

     cheers,

         Rolf Turner