I am trying to save a data.frame from R so that it can be read from Excel. I have done this with several other data.frames that have the same structure as the one I refer to now, so far without problems. But for some reason when I try to save this data.frame and then open it with Excel, many of the numerical values in the columns FreqDev and LengthDev are not read by Excel. Instead, the rows show a string of "#" symbols.
My data.frame looks like this:
head(RegPartV)
LogFreq Word PhonCV WordClass FreqDev LengthDev Irregular
1277 28.395 geweest CV-CVVCC V 5.464336 -1.1518498 FALSE
903 25.647 gemaakt CV-CVVCC V 4.885296 -1.1518498 FALSE
752 23.304 gehad CV-CVC V 4.391595 -2.1100420 FALSE
610 22.765 gebracht CV-CCVCC V 4.278021 -0.6727537 FALSE
1312 22.041 gezegd CV-CVCC V 4.125465 -1.6309459 FALSE
647 21.987 gedaan CV-CVVC V 4.114086 -1.6309459 FALSE
The type of information in the data.frame is:
str(RegPartV)
'data.frame': 2096 obs. of 7 variables:
$ LogFreq : num 28.4 25.6 23.3 22.8 22 ...
$ Word : chr "geweest" "gemaakt" "gehad" "gebracht" ...
$ PhonCV : chr "CV-CVVCC" "CV-CVVCC" "CV-CVC" "CV-CCVCC" ...
$ WordClass: Factor w/ 1 level "V": 1 1 1 1 1 1 1 1 1 1 ...
$ FreqDev : num 5.46 4.89 4.39 4.28 4.13 ...
$ LengthDev: num -1.152 -1.152 -2.11 -0.673 -1.631 ...
$ Irregular: logi FALSE FALSE FALSE FALSE FALSE FALSE ...
What is strange is that if I put my mouse over the numerical cells that now have only # symbols (in the excel file), I see a trace of the numbers that used to be there in the original R data.frame. For example, the values of these columns for the first row in the data.frame are:
>RegPartV[1,c(5,6)]
FreqDev LengthDev
1277 5.464336 -1.15185
And if I put my mouse over the Excel cells (that contain only # symbols) corresponding to the same values I just showed, I see:
54643356148468
and
-115184982188519
So the numbers are still there, but for some reason either R or Excel lost count of where the decimal was.
The method I am using to save the data.frame (and that I've used for structurally equivalent data.frame) is:
write.table(RegPartV,file="RegPartV",quote=F,sep="\t",row.names=F,col.names=T)
Then I open the file with Excel and I would expect to see all the info there, for some reason I'm having this numeric problem with this particular data.frame.
Any suggestions to get an Excel-readable data.frame are very welcome.
Thanks in advance.
From your problem description I suspect that you have "," as the default decimal separator in Excel. Either change the default in Excel or add dec=","
to the write.table
command.
That isn't actually an error: "#" means that a string/value is too long to fit into column. Widen the column and you'll see proper contents.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.