excel spreadsheet import/export issue in R - r

I have an excel file with the first column completely blank. When i read it into R using read.xls the first column does not appear. However, when I export the data set, that column reappears but with numbers in it corresponding to the row.
My issue is that I do need my expoted xls sheet to retain that first blank column (including no header/variable name).
How do I retain that column or make sure the exported spreadsheet has it?

Related

why columns of csv file are shifting one cell to the right after downloading?

I have a csv file, on which i am running a R script.While previewing the file in google mail, the first cell is having value ";User". After getting downloaded, the the first cell is empty and the ";User " along with other column names is shifting by one cell to right.
Does anybody have a clue , as why it may happen?

Loosing column of data when importing large csv file with read_csv

I'm importing a 2.2GB csv file with 24 million rows using read_csv(). One of the columns (vital sign_date_time), a character variable, is not being read and is importing with only NA values.
I've opened the .csv file up in SQLServer and can confirm the data is there in the file. I've broken the large file up into smaller chunks in macOS terminal. When I import the smaller files, again with read_csv(), the data is also present.
I'm using the import dialog box in RStudio to minimize any typing errors. In the data view section of the dialog box, it shows only NA data in the column in question and is trying to import the column as a logical field. I've tried manually changing this to character type and it still reads only NA values.
Here's a screenshot of the dialog box:
Any ideas about what might be happening?
Thanks.
Take care,
Jeff
I was bitten by a similar problem recently, so this is a guess based on that experience.
By default, if the 1000 first entries of a column are NA, readr::read_csv will automatically set all values of this column to NA. You can control this by setting the guess_max argument. Here is the documentation:
guess_max: Maximum number of records to use for guessing column types.
For example,
library(readr)
dat <- read_csv("file.csv", guess_max=100000)

How to split one column containing several values so each column only contains one value?

starting situation as follows:
I've got a csv files with roughly 3000 rows, but only 1 column. In each of the rows there are several values included.
Now I want to assign only one value per column.
How do I manage to do that?
convert the file into txt format and then open the data using MS excel. Don't directly open the file. Open it using Open option in file menu. When you do this a text wizard will appear. You can then split your data by using delimited such as commas, spaces and form multiple columns. Once you are done with it, you save the file in csv format

Read excel data as is using readxl in R

I have to read an excel file in R. The excelfile has a column with values such as 50%,20%... and another column with dates in the format "12-December-2017" but R converts both the column datas.
I am using readxl package and i specified in col_types parameter all the columns to be read as text but when i check the dataframe all the column types are characters but the percentage data and date changes to decimals and numbers respectively.
excelfile2<-read_excel(filePath,col_types=rep("text",8))
I want to read the excel file as is.Any help will be appreciated.
This is because what you visualize inside the Excel is not what actually is stored.
For example, if in excel you visualize "12-December-2017", what is stored in reality is the number of days since 1-1-1899.
My suggestion is to open the Excel file with the TextReader so you have a grasp what really you are reading in R.
Then, you can either define everything as text in excel or you can apply some transformations in R in order to convert the days since 1-1-1899 into a POSIXct format.

CSV column formatting while spooling a csv file in sqlplus

How do i extract a number formatted column when i spool to a csv file from unix when the column is varchar in database?
Number format in CSV is 5.05291E+12
should actually be 5052909272618
This problem is not a Unix or ksh problem, but an Excel problem. Assuming Excel is the default application for a .csv file, When you double-click to open in Excel, it makes the column type "General" by default and you get the scientific notation instead of the text value as expected. If your numeric data has leading zeroes they will be removed also.
One way to fix is to start Excel (this example in the 2010 version), the go to Data/get external data/from text, follow the wizard making sure to set the "column data format" to "text" for the column that contains your large number (click on the column in the "data preview" section first). Leading zeroes will be preserved also.
You could code a vba macro that would open with all columns as text (a little searching will show you some examples) but there seems to be no place to tell Excel to treat columns as "text" by default.
There was need to develop report and I was also facing the same issue.i found that there is one workaround/solution. e.g.
your table name --> EMPLOYEE
contains 3 columns colA,colB,colC. the problem is with colB. after connecting to sqlplus you can save the the data in spool file as :
select colA|| ','''||colB||''',' ||colC from employee
sample result:
3603342979,'8938190128981938262',142796283 .
when excel opens the file it displays the result "as-it-is"

Resources