I have an Excel data file with two columns: the first is a column of dates in the format dd-mmm-yy and the second is a column of (jogging) times in minutes. I saved the Excel file as a .CSV file. The name of the file is RunningD.CSV.
First, I extracted the data in R with:
dataD<- read.csv("RunningD.csv")
I then plotted the data in R with the following code:
qplot(as.Date(dataD$Date,'%d-%b-%y'), dataD$Time, xlab="Date",
ylab="Time (mins)", color=dataD$Time)
However, the x-axis only shows the month of the dates, not, as desired, the day-month-year.
See data plot
Does anyone know why?
Thanks in advance.
Related
I have a data in excel with 13 columns defined as year and months. I want to run time series analysis but finds it difficult to plot the data. Please how can I convert this file such that I can analyse the data?
My excel file
Tried plotting but gets error. Error reads "can not plot morethan 10 series"
Say your data is df.
Using base R,
rownames(df) <- df$Year
df$Year <- NULL
ts(as.vector(t(as.matrix(dummy.df))),
start=..., end=..., frequency=12)
You may change start and end depends on your data.
I have this column is date of birth. Is there any R function or any method to solve this date problem, the dates in Excel are ok. But when I read the file in R I am getting wrong dates as below:
2047-11-03
2064-06-08
1098639-10-01
377383-01-18
1979098-01-27
-177103-09-27
-186092-08-24
1612569600
-236822400
the original dates in excel as below
01/11/1977
07/06/1994
11/09/1982
07/05/1974
19/11/1992
06/12/1967
29/10/1967
06/02/2021
01/07/1962
I used the following to imports the data
df<- import_list("df.xlsx")
everyone I am just a beginner of R,so following code or question might misunderstand R function. Hopes you guys don't mind it.
I got hundreds ERA Interim Daily Precipitation data from ECMWF.
Each monthly NetCDF file contain twice per day precipitation and extract them by Longitude & Latitude.
Finally convert to CSV file,but itself store (12:00 ;00:00) two columns for
same days rainfall.
Image of output CSV
Ideally ,I would like to obtain single day rainfall for whole year or month. But, don't know how to do it in R.
Q1: Is there any library or function support merge columns names and keep
same dates?
Q2: However, I am not sure lubridate library can accomplish or others will be
better.
-----Thanks for any answers---------
If somebody want to view NetCDF file and .csv file ,you can get from my google driver:
https://drive.google.com/drive/folders/1ogQp_-MlvmJCDmzm38dXHbUmWAM6hi1v?usp=sharing
P.S In Google Drive SumMonth.csv is extract result
R Code:
library(raster)
library(ncdf4)
f <- list.files("C:/Users/asus/Downloads/extract",
pattern = "*.nc", full.names = TRUE)
ncloop <-lapply(f,nc_open)# Read whold folder nc.file
brick <-lapply(f,brick,varname = "tp")
brick2 <-stack(brick)# Combine all month
dim(brick2)#check dim right
##### input location file with Lon&Lat
pointCoordinates <- read.table("C:/Users/asus/Downloads/pointFile.csv",
header = TRUE, sep = ",",stringsAsFactors=FALSE)
coordinates(pointCoordinates) <- ~Long + Lat # Assign XY for extract
rasValue=extract(brick2, pointCoordinates)#extract
combinePointValue=cbind(pointCoordinates,rasValue)#construct database
## Outout as csv
cc <- as.data.frame(combinePointValue)
write.csv(cc,file ="SumMonth.csv")
I believe this may have been asked a lot, but I have data in the format below and I can't apply the existing answers to my questions (including this nearest answer - R - Stock market data from csv to xts).
Date,AX,BY,CZ
5/21/2015,817,57,22.55
5/22/2015,810.5,57.45,22.7
So the data is in the format of DATE, CLOSE of stock AX, CLOSE of stock BY, CLOSE of stock CZ. Just to specify, the date is in the format shown above that is, m/d/YYYY where months and days are flexible in digits (one or two) while year is always in the format of four digits. The file is saved as CSV.
I wanted to use this code to convert the "zoo" read data to xts.
x <- as.xts(z)
The xts and zoo vignettes aren't really newbie friendly, so I hope someone can give a little nudge.
You might look at the examples in the help page for read.zoo. You need to tell the function about the header, the date format, and the separator between values. To read the data from a text string would look like
library(xts)
z <- read.zoo(header=TRUE, format="%m/%d/%Y", sep=",",
text ="Date,AX,BY,CZ
5/21/2015,817,57,22.55
5/22/2015,810.5,57.45,22.7")
z <- as.xts(z)
To read from the file fileName, replace text=... with file="filename".
I have a result.csv file to which contains information in the following format :
date,tweets
2015-06-15,tweet
2015-06-15,tweet
2015-06-12,tweet
2015-06-11,tweet
2015-06-11,tweet
2015-06-11,tweet
2015-06-08,tweet
2015-06-08,tweet
i want to plot a frequency polygon with number of entries corresponding to each date as y axis and dates as x axis
i have tried the following code :
pf<-read.csv("result.csv")
library(ggplot2)
qplot(datetime, data =pf, geom = "freqpoly")
but it shows the following error :
geom_path: Each group consist of only one observation. Do you need to adjust the group aesthetic?
can anyone tell me how to solve this problem. I am totally new to R so any kind of guidance will be of great help to me
Your issue is that you are trying to treat datetime as continuous, but it's imported it as a factor (discrete/categorical). Let's convert it to a Date object and then things should work:
pf$datetime = as.Date(pf$datetime)
qplot(datetime, data =pf, geom = "freqpoly")
Based on your code, I assume that the result.csv has a header: datetime, atweet. By default, read.csv takes the first line of the CSV file as column names. That means you will be able to access the two columns with pf$datetime and pf$atweet.
If you look at the documentation of read.csv, you will find that stringsAsFactors = default.stringsAsFactors(), which is FALSE. That is, the strings from CSV files are kept as factors.
Now, even if you change the value of stringsAsFactors, you still get the same error. That is because ggplot does not know how to order the dates, as it does not recognize the strings as such.
To transform the strings into logical dates, you can use strptime.
Here is the working example:
pf<-read.csv("result.csv", stringsAsFactors=FALSE)
library(ggplot2)
qplot(strptime(pf$datetime, "%Y-%m-%d"), data=pf, geom='freqpoly')