I'm trying to read an Excel file in R, with two columns containing dates. Now here is my problem, when I view my data file in R, most of the dates are in the good format, but some were transformed into number that don't make sense at all. I joined images to show the different outputs from R/Excel.
(Only pay attention to the columns "ArrivalDate" and ActlFlightDate")
Output seen from R
Output seen from Excel
My question is, how, in R, can I make those numbers become the date they are supposed to be? Especially since the class of the elements in those columns are characters.
Thank you in advance!
Your dates in your excel file are different formats. That is why some are to left side of column and some are to right side of column in the spreadsheet. They are probably mixed between an actual excel date format and a text or general. You should copy the columns to new columns and highlight the new column and right click and change format until all your dates are uniform. Then you can import to R and have consistent dates data.
Our excel sheet is formatted in a strange manner. Some headers are located in the first row, others are located in either the 2nd,3rd, or 4th row. Beneath the 4th row is the first subset of data we want to generate graphs from, there are multiple subsets as you go down the excel sheet. Each of these subsets is separated by an empty row. The first column is dedicated to the name of the source of the data. For example in the first column and 5th row, there is a label called "communications" and to the right is the data. The rows in the first column under "communications" are empty until the next label. We need to be able to read the separate subsets in shiny to generate individual graphs. How do you recommend we go about this? We are fairly new to R and are lost on where to go.
I'm attempting to create a specifically formatted header to append to a data frame I have created in R.
The essence of my problem is that it seems increasingly difficult (maybe impossible?) to create a header that breaks away from a typical one row by one column framework, without merging the underlying table, using the dataframe concept in R.
The issue stems from me not being able to figure out a way to import this particular format of a header into R through methods such as read.csv or read.xlsx which preserve the format of the header.
Reading in a header of this format into R from a .csv or .xlsx is quite ugly and doesn't preserve the original format. The format of the header I'm trying to create and append to an already existing dataframe I have of 17 nameless columns in R could be represented in such a way:
Where the number series of 1 - 17 represents the already existing data frame of 17 nameless columns of data that I have created in R in which I wish to append to this header. Could anyone point me in the right direction?
You are correct that this header will not work within R. The data frame only supports single header values and wont do something akin to a merged cell in excel.
However if you simply want to export your data to an .csv or .xlsx (use write.csv) then just copy your header in, that could work.
OR
You could add in a factor column to your data frame to capture the information contained in the top level of your header.
I am currently working on a dataframe which looks like this:
data.frame(Plot_ID=c(1,1,1,1,1,2,2,2,2,3,3,3,3,3,3,3,3,3,4,4,4),
Species=c("a","a","a","b","b","c","c","b","b","b","b","d","d","d","e","e","e","e","a","a","a")
DBH=c(12,32,44,11,14,66,43,22,88,22,23,45,354,6,7,45,12,11,5,6,8))
DBH is just the diameter of the species. What I want to create is a species accumulation curve, however the packet specaccum only allows for a different format which is like this:
data.frame (Spec1=c(1,0,2,3),Spec2=c(0,0,0,4),Spec3=c(1,1,2,3))
My data has over 3000 rows, with more that a hundred species which makes it very difficult to reformat the data accordingly. Is there a way to easily reformat the data, or to use the data like it is with a different package?
Ok after a while I remembered the pivot-table of LibreOffice, where you can exactly format the data to have the species in columns, each plot in a row and the sum in between.
For that, create a 3rd column which includes only the number 1, your data should look like this:
d1<-data.frame(Plot_ID=c(1,1,2,2,3,3),
Species=c("a","b","a","c","d","c"),
Count=c(1,1,1,1,1,1))
Export the data frame as .csv file using
write.table(d1, "~/path/of/desire/d1.csv")
Import the csv. table in Libreoffice by using space as separator. Delete the first column as it is the internal R-ID and shifts the headings.
Mark your data and go to Data->Pivot-table, select marked data and click OK.
You will see something like this
Loai.cay is the Species here. Drag the Species to the column-cields, the Plot_ID to the row-fields and the Count to the data-fields, as it is the case in the picture. Press OK and copy the result in a extra table. Press CTRL+SHIFT+S and select save as .csv file. Import the csv-file in R and use the specaccum function as described in the description of the function.
Hope this helps someone else than me.