Re: [R] How to aggregate values in corresponding dataframes

2019-03-25 Thread lily li
Each dataframe is a gridded file, so I want to add the values at
corresponding grid cells from all the dataframes.

On Mon, Mar 25, 2019 at 6:22 PM Rui Barradas  wrote:

> Sorry, I forgot to ask something.
>
> When you say you want to add the df's values, what exactly do you mean?
> All of the values, by row, by column, what?
>
> Rui Barradas
>
> Às 10:20 de 25/03/2019, Rui Barradas escreveu:
> > Hello,
> >
> > Maybe something like this?
> > Note that you *never* need to set header = FALSE, it already is the
> > default of read.table. You would have to with read.csv.
> >
> >
> > old_dir <- setwd("~/directory")
> > f1990 <- list.files(pattern = "^199.*\\.txt$")
> > r1990 <- lapply(f1990, read.table)
> > setwd(old_dir)
> >
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> >
> > Às 08:30 de 25/03/2019, lily li escreveu:
> >> Hi R users,
> >>
> >> I have multiple dataframes in a directory, and with the same postfix
> >> ".txt". Each dataframe is a gridded file with just values, but each
> value
> >> represents one grid cell. There are many years, and each year has 12
> >> months, so there are many such files. For each year, I want to read the
> >> corresponding year's files and add the values of the dataframes, but I
> >> don't know how to do that. For example, the file names are
> >> 1990_file01.txt
> >> 1990_file02.txt
> >> ...
> >> 1990_file12.txt
> >> 1991_file01.txt
> >> ...
> >> 1991_file12.txt
> >> ...
> >>
> >> And my code is like this:
> >> f1990 = list.files("~/directory", pattern = "^1990(.*).txt$")
> >> for(i in 1:length(f1990)){
> >> r1990 = read.table(paste('~/directory',f1990[i],sep='/'),head=F)
> >> }
> >>
> >> Could you provide some help on this? Thanks very much.
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide
> >> http://www.R-project.org/posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> > http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to aggregate values in corresponding dataframes

2019-03-25 Thread lily li
Hi R users,

I have multiple dataframes in a directory, and with the same postfix
".txt". Each dataframe is a gridded file with just values, but each value
represents one grid cell. There are many years, and each year has 12
months, so there are many such files. For each year, I want to read the
corresponding year's files and add the values of the dataframes, but I
don't know how to do that. For example, the file names are
1990_file01.txt
1990_file02.txt
...
1990_file12.txt
1991_file01.txt
...
1991_file12.txt
...

And my code is like this:
f1990 = list.files("~/directory", pattern = "^1990(.*).txt$")
for(i in 1:length(f1990)){
r1990 = read.table(paste('~/directory',f1990[i],sep='/'),head=F)
}

Could you provide some help on this? Thanks very much.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to create gridded data

2019-03-24 Thread lily li
Now I have new question about this post. If the grid coordinates in DF1 are
not complete, i.e. there are missing coordinates, how to fill these with
-99 in the exported DF2? Thanks.

On Thu, Nov 15, 2018 at 10:57 PM David L Carlson  wrote:

> It would depend on the format of the gridded data. Assuming it is a data
> frame like DF2 in my earlier answer, you just reverse the steps:
>
> > DF2
>  110.5 111 111.5 112
> 46 6.1 4.5   7.8 5.5
> 45.5   3.2 5.0   1.8 2.0
>
> > DF3 <- data.frame(as.table(as.matrix(DF2)))
>   Var1  Var2 Freq
> 1   46 110.5  6.1
> 2 45.5 110.5  3.2
> 3   46   111  4.5
> 4 45.5   111  5.0
> 5   46 111.5  7.8
> 6 45.5 111.5  1.8
> 7   46   112  5.5
> 8 45.5   112  2.0
>
> But the latitude and longitude get converted to factors and we lose the
> column names:
>
> > DF3 <- data.frame(as.table(as.matrix(DF2)))
> > colnames(DF3) <- c("latitude", "longitude", "Precip")
> > DF3$latitude <- as.numeric(as.character(DF3$latitude))
> > DF3$longitude <- as.numeric(as.character(DF3$longitude))
>
> --------
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
> From: lily li 
> Sent: Tuesday, November 13, 2018 10:50 PM
> To: David L Carlson 
> Cc: Sarah Goslee ; R mailing list <
> r-help@r-project.org>
> Subject: Re: [R] How to create gridded data
>
> Thanks, Sarah's answer helps the question. Now how to change the gridded
> data back to DF1 format? I don't know how to name the format, thanks.
>
> On Tue, Nov 13, 2018 at 10:56 PM David L Carlson <mailto:dcarl...@tamu.edu>
> wrote:
> Sarah's answer is probably better depending on what you want to do with
> the resulting data, but here's a way to go from your original DF1 to DF2:
>
> > DF1 <- structure(list(latitude = c(45.5, 45.5, 45.5, 45.5, 46, 46, 46,
> + 46), longitude = c(110.5, 111, 111.5, 112, 110.5, 111, 111.5,
> + 112), Precip = c(3.2, 5, 1.8, 2, 6.1, 4.5, 7.8, 5.5)),
> + class = "data.frame", row.names = c(NA, -8L))
> >
> # Convert to table with xtabs()
> > DF2 <- xtabs(Precip~latitude+longitude, DF1)
> >
>
> # Reverse the order of the latitudes
> > DF2 <- DF2[rev(rownames(DF2)), ]
> > DF2
> longitude
> latitude 110.5 111 111.5 112
> 46 6.1 4.5   7.8 5.5
> 45.5   3.2 5.0   1.8 2.0
>
> # Convert to a data frame
> > DF2 <- as.data.frame.matrix(DF2)
> > DF2
>  110.5 111 111.5 112
> 46 6.1 4.5   7.8 5.5
> 45.5   3.2 5.0   1.8 2.0
>
> 
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
>
> -Original Message-
> From: R-help <mailto:r-help-boun...@r-project.org> On Behalf Of Sarah
> Goslee
> Sent: Tuesday, November 13, 2018 8:16 AM
> To: lily li <mailto:chocol...@gmail.com>
> Cc: r-help <mailto:r-help@r-project.org>
> Subject: Re: [R] How to create gridded data
>
> If you want an actual spatial dataset, the best place to ask is R-sig-geo
>
> R has substantial capabilities for dealing with gridded spatial data,
> including in the sp, raster, and sf packages.
>
> Here's one approach, creating a SpatialGridDataFrame, which can be
> exported in any standard raster format using the rgdal package.
>
> DF2 <- DF1
> coordinates(DF2) <- ~longitude + latitude
> gridded(DF2) <- TRUE
> fullgrid(DF2) <- TRUE
>
> I recommend Roger Bivand's excellent book:
>
> https://urldefense.proofpoint.com/v2/url?u=https-3A__www.springer.com_us_book_9781461476177&d=DwMFaQ&c=ODFT-G5SujMiGrKuoJJjVg&r=veMGHMCNZShld-KX-bIj4jRE_tP9ojUvB_Lqp0ieSdk&m=vZqNKoDe8N1TzBzeK12g2oa0cBS8VD6NDCs-hUhvt5o&s=B73PwZQrdKUmM1ML2Y5zjaEz7xqkHlzBDCrhluogK2U&e=
>
> and there are abundant web tutorials.
>
> Sarah
> On Tue, Nov 13, 2018 at 2:22 AM lily li <mailto:chocol...@gmail.com>
> wrote:
> >
> > Hi R users,
> >
> > I have a question about manipulating data. For example, I have DF1 as the
> > following, how to transform it to a gridded dataset DF2? In DF2, each
> value
> > Precip is an attribute of the corresponding grid cell. So DF2 is like a
> > spatial surface, and can be imported to ArcGIS. Thanks for your help.
> >
> > DF1
> > latitude   longitude   Precip
> > 45.5   110.5 3.2
> > 45.5   1115.0
> > 45.5   111.5 1.8
> > 45.5   1122.0
> > 46

Re: [R] How to create gridded data

2018-11-13 Thread lily li
Thanks, Sarah's answer helps the question. Now how to change the gridded
data back to DF1 format? I don't know how to name the format, thanks.

On Tue, Nov 13, 2018 at 10:56 PM David L Carlson  wrote:

> Sarah's answer is probably better depending on what you want to do with
> the resulting data, but here's a way to go from your original DF1 to DF2:
>
> > DF1 <- structure(list(latitude = c(45.5, 45.5, 45.5, 45.5, 46, 46, 46,
> + 46), longitude = c(110.5, 111, 111.5, 112, 110.5, 111, 111.5,
> + 112), Precip = c(3.2, 5, 1.8, 2, 6.1, 4.5, 7.8, 5.5)),
> + class = "data.frame", row.names = c(NA, -8L))
> >
> # Convert to table with xtabs()
> > DF2 <- xtabs(Precip~latitude+longitude, DF1)
> >
>
> # Reverse the order of the latitudes
> > DF2 <- DF2[rev(rownames(DF2)), ]
> > DF2
> longitude
> latitude 110.5 111 111.5 112
> 46 6.1 4.5   7.8 5.5
> 45.5   3.2 5.0   1.8 2.0
>
> # Convert to a data frame
> > DF2 <- as.data.frame.matrix(DF2)
> > DF2
>  110.5 111 111.5 112
> 46 6.1 4.5   7.8 5.5
> 45.5   3.2 5.0   1.8 2.0
>
> 
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77843-4352
>
>
> -Original Message-
> From: R-help  On Behalf Of Sarah Goslee
> Sent: Tuesday, November 13, 2018 8:16 AM
> To: lily li 
> Cc: r-help 
> Subject: Re: [R] How to create gridded data
>
> If you want an actual spatial dataset, the best place to ask is R-sig-geo
>
> R has substantial capabilities for dealing with gridded spatial data,
> including in the sp, raster, and sf packages.
>
> Here's one approach, creating a SpatialGridDataFrame, which can be
> exported in any standard raster format using the rgdal package.
>
> DF2 <- DF1
> coordinates(DF2) <- ~longitude + latitude
> gridded(DF2) <- TRUE
> fullgrid(DF2) <- TRUE
>
> I recommend Roger Bivand's excellent book:
> https://www.springer.com/us/book/9781461476177
>
> and there are abundant web tutorials.
>
> Sarah
> On Tue, Nov 13, 2018 at 2:22 AM lily li  wrote:
> >
> > Hi R users,
> >
> > I have a question about manipulating data. For example, I have DF1 as the
> > following, how to transform it to a gridded dataset DF2? In DF2, each
> value
> > Precip is an attribute of the corresponding grid cell. So DF2 is like a
> > spatial surface, and can be imported to ArcGIS. Thanks for your help.
> >
> > DF1
> > latitude   longitude   Precip
> > 45.5   110.5 3.2
> > 45.5   1115.0
> > 45.5   111.5 1.8
> > 45.5   1122.0
> > 46  110.5 6.1
> > 46  1114.5
> > 46  111.5 7.8
> > 46  1125.5
> > ...
> >
> >
> > DF2
> > 6.1   4.5   7.8   5.5
> > 3.2   5.0   1.8   2.0
> > ...
> >
>
>
> --
> Sarah Goslee (she/her)
> http://www.numberwright.com
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to create gridded data

2018-11-12 Thread lily li
Hi R users,

I have a question about manipulating data. For example, I have DF1 as the
following, how to transform it to a gridded dataset DF2? In DF2, each value
Precip is an attribute of the corresponding grid cell. So DF2 is like a
spatial surface, and can be imported to ArcGIS. Thanks for your help.

DF1
latitude   longitude   Precip
45.5   110.5 3.2
45.5   1115.0
45.5   111.5 1.8
45.5   1122.0
46  110.5 6.1
46  1114.5
46  111.5 7.8
46  1125.5
...


DF2
6.1   4.5   7.8   5.5
3.2   5.0   1.8   2.0
...

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to exclude certain keywords in strings

2018-10-11 Thread lily li
I just figured this out, which seems to be a simple question. I just used
gsub("_temp.csv","","StationName1_temp.csv").



> Hi R users,
>
> I don't know how to extract certain words in strings. For example, if I
> have strings like the formats "StationName1_temp.csv",
> "StationName2_temp.csv", etc. How to get strings like these "StationName1",
> "StationName2", etc? That is to say, I want to exclude the keywords
> "_temp.csv", but I could not find a clue online. Thanks for your help.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] how to exclude certain keywords in strings

2018-10-11 Thread lily li
Hi R users,

I don't know how to extract certain words in strings. For example, if I
have strings like the formats "StationName1_temp.csv",
"StationName2_temp.csv", etc. How to get strings like these "StationName1",
"StationName2", etc? That is to say, I want to exclude the keywords
"_temp.csv", but I could not find a clue online. Thanks for your help.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Open netcdf file in linux

2018-09-18 Thread lily li
I did not set the correct path for the .nc file earlier. Now it is working
properly.



> I find your response confusing still... did you now no longer need help?
>
> If you are still puzzled, then what does
>
> file.info("file.nc")
>
> return?
>
> Do you see that file in your current directory via your operating system?
>
> On September 17, 2018 11:53:22 PM PDT, lily li 
> wrote:
> >Thanks, you are right that the file path is not correct. I just typed:
> >nc_open("file.nc"), and it gave the error above.
> >
> >On Tue, Sep 18, 2018 at 1:33 PM, Jeff Newmiller
> >
> >wrote:
> >
> >> I really don't know how you expect an answer when you don't show what
> >you
> >> did or pointed us to an example of a file that yields this error. My
> >best
> >> blind guess is that you have not given the name of an ncdf file to
> >the
> >> function.
> >>
> >> On September 17, 2018 9:44:45 PM PDT, lily li 
> >wrote:
> >> >Hi R users,
> >> >
> >> >I have installed ncdf4 package in R from the linux terminal, but
> >have
> >> >met
> >> >this problem when using nc_open to open a .nc file. What is the
> >> >problem?
> >> >Any help would be appreciated.
> >> >
> >> >Error in R_nc4_open: Is a directory
> >> >
> >> >   [[alternative HTML version deleted]]
> >> >
> >> >__
> >> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> >https://stat.ethz.ch/mailman/listinfo/r-help
> >> >PLEASE do read the posting guide
> >> >http://www.R-project.org/posting-guide.html
> >> >and provide commented, minimal, self-contained, reproducible code.
> >>
> >> --
> >> Sent from my phone. Please excuse my brevity.
> >>
>
> --
> Sent from my phone. Please excuse my brevity.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Problem in installing rgdal package in linux

2018-09-18 Thread lily li
Hi all,

I am installing rgdal package in linux for R, and got the error below. I
typed: $ install.packages("rgdal", repos= "http://cran.us.r-project.org";)

What is the problem and how to correct it? Thanks for your kind help.

== print the error message here

downloaded 1.6 MB


* installing *source* package ‘rgdal’ ...

** package ‘rgdal’ successfully unpacked and MD5 sums checked

configure: R_HOME: /usr/lib64/R

configure: CC: gcc -m64 -std=gnu99

configure: CXX: g++ -m64

configure: C++11 support available

configure: rgdal: 1.3-4

checking for /usr/bin/svnversion... yes

configure: svn revision: 766

checking for gdal-config... no

no

configure: error: gdal-config not found or not executable.

ERROR: configuration failed for package ‘rgdal’

* removing ‘/directory/R/x86_64-redhat-linux-gnu-library/3.5/rgdal’


The downloaded source packages are in

‘/tmp/RtmpplM8mi/downloaded_packages’

Warning message:

In install.packages("rgdal") :

  installation of package ‘rgdal’ had non-zero exit status

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Open netcdf file in linux

2018-09-17 Thread lily li
Thanks, you are right that the file path is not correct. I just typed:
nc_open("file.nc"), and it gave the error above.

On Tue, Sep 18, 2018 at 1:33 PM, Jeff Newmiller 
wrote:

> I really don't know how you expect an answer when you don't show what you
> did or pointed us to an example of a file that yields this error. My best
> blind guess is that you have not given the name of an ncdf file to the
> function.
>
> On September 17, 2018 9:44:45 PM PDT, lily li  wrote:
> >Hi R users,
> >
> >I have installed ncdf4 package in R from the linux terminal, but have
> >met
> >this problem when using nc_open to open a .nc file. What is the
> >problem?
> >Any help would be appreciated.
> >
> >Error in R_nc4_open: Is a directory
> >
> >   [[alternative HTML version deleted]]
> >
> >__
> >R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >https://stat.ethz.ch/mailman/listinfo/r-help
> >PLEASE do read the posting guide
> >http://www.R-project.org/posting-guide.html
> >and provide commented, minimal, self-contained, reproducible code.
>
> --
> Sent from my phone. Please excuse my brevity.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Open netcdf file in linux

2018-09-17 Thread lily li
Hi R users,

I have installed ncdf4 package in R from the linux terminal, but have met
this problem when using nc_open to open a .nc file. What is the problem?
Any help would be appreciated.

Error in R_nc4_open: Is a directory

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to plot gridded data

2018-09-13 Thread lily li
I think it may be feasible to transform the dataset DF, so that the column
names lat_lon can be a surface, where the values locate at each surface.
But I don't know how to transform DF.

On Fri, Sep 14, 2018 at 10:02 AM, lily li  wrote:

> Hi Petr,
>
> I have merged the data using cbind. The dataset is like this:
> DF
> lat1_lon1  lat1_lon2  lat1_lon3  ...  lat2_lon1
>   1.20   1.30  2.11  ... 1.28
>   1.50   1.81  3.12  ... 2.34
>   2.41   2.22  1.56  ... 2.50
>   3.11   4.21  2.12  ... 3.21
>
> The other file is a shapfile, which I can open using readOGR. Then it
> shows a polygon according to geographical latitude and longitude in
> degrees. How to overlay the values in DF onto the polygon? note that DF has
> the coordinates for a rectangular box that includes the shapefile, but is
> larger. I don't know how to do this. Thanks for your help.
>
> On Wed, Sep 12, 2018 at 3:22 PM, PIKAL Petr 
> wrote:
>
>> Hi
>>
>> 1. Read files/lines into R ?read.table, ?read.lines
>> 2. Merge files according to your specification ?merge, ?rbind
>> 3. Plot values by suitable command(s) ?plot, ?ggplot
>> 4. If you want more specific answer, please post more specific question,
>> preferably with concise and clear example.
>> 5. Avoid posting in HTML
>>
>> Cheers
>> Petr
>>
>> > -Original Message-
>> > From: R-help  On Behalf Of lily li
>> > Sent: Wednesday, September 12, 2018 8:55 AM
>> > To: R mailing list 
>> > Subject: [R] how to plot gridded data
>> >
>> > Hi R users,
>> >
>> > I have a question about plotting gridded data. I have the files
>> separately, but do
>> > not know how to combine them. For example, each txt file has daily
>> > precipitation data at a specific grid cell, named pr_lat_lon.txt. How
>> to plot all
>> > txt files for one surface (which is rectangular in this case), or how
>> to combine
>> > the txt files together? Thanks.
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>> Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních
>> partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady
>> -ochrany-osobnich-udaju/ | Information about processing and protection
>> of business partner’s personal data are available on website:
>> https://www.precheza.cz/en/personal-data-protection-principles/
>> Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou
>> důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení
>> odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any
>> documents attached to it may be confidential and are subject to the legally
>> binding disclaimer: https://www.precheza.cz/en/01-disclaimer/
>>
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] how to plot gridded data

2018-09-13 Thread lily li
Hi Petr,

I have merged the data using cbind. The dataset is like this:
DF
lat1_lon1  lat1_lon2  lat1_lon3  ...  lat2_lon1
  1.20   1.30  2.11  ... 1.28
  1.50   1.81  3.12  ... 2.34
  2.41   2.22  1.56  ... 2.50
  3.11   4.21  2.12  ... 3.21

The other file is a shapfile, which I can open using readOGR. Then it shows
a polygon according to geographical latitude and longitude in degrees. How
to overlay the values in DF onto the polygon? note that DF has the
coordinates for a rectangular box that includes the shapefile, but is
larger. I don't know how to do this. Thanks for your help.

On Wed, Sep 12, 2018 at 3:22 PM, PIKAL Petr  wrote:

> Hi
>
> 1. Read files/lines into R ?read.table, ?read.lines
> 2. Merge files according to your specification ?merge, ?rbind
> 3. Plot values by suitable command(s) ?plot, ?ggplot
> 4. If you want more specific answer, please post more specific question,
> preferably with concise and clear example.
> 5. Avoid posting in HTML
>
> Cheers
> Petr
>
> > -Original Message-
> > From: R-help  On Behalf Of lily li
> > Sent: Wednesday, September 12, 2018 8:55 AM
> > To: R mailing list 
> > Subject: [R] how to plot gridded data
> >
> > Hi R users,
> >
> > I have a question about plotting gridded data. I have the files
> separately, but do
> > not know how to combine them. For example, each txt file has daily
> > precipitation data at a specific grid cell, named pr_lat_lon.txt. How to
> plot all
> > txt files for one surface (which is rectangular in this case), or how to
> combine
> > the txt files together? Thanks.
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních
> partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/
> zasady-ochrany-osobnich-udaju/ | Information about processing and
> protection of business partner’s personal data are available on website:
> https://www.precheza.cz/en/personal-data-protection-principles/
> Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou
> důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení
> odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any
> documents attached to it may be confidential and are subject to the legally
> binding disclaimer: https://www.precheza.cz/en/01-disclaimer/
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] how to plot gridded data

2018-09-11 Thread lily li
Hi R users,

I have a question about plotting gridded data. I have the files separately,
but do not know how to combine them. For example, each txt file has daily
precipitation data at a specific grid cell, named pr_lat_lon.txt. How to
plot all txt files for one surface (which is rectangular in this case), or
how to combine the txt files together? Thanks.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to average values from grid cells with coordinates

2018-05-21 Thread lily li
Hi Jim,

Thanks. It works. I now have more complex problems. If at each blackcell,
there are two variables such as pop and mood. For each variable, there are
daily records in one year, so 365 records for pop and 365 records for mood.
The averaged values for the redcells should be daily records too. What kind
of format do you recommend for this problem? Right now, I just get the
latitudes and longitudes into a dataframe. Thanks.

On Sun, May 20, 2018 at 3:52 AM, Jim Lemon  wrote:

> Hi lily,
> It's not too hard to do it using dataframes. Getting the indexing
> right is usually that hardest part:
>
> # these values are the centers of the black cells
> lat<-rep(28:38,11)
> lon<-rep(98:108,each=11)
> pop<-sample(80:200,121)
> # just use the data.frame function
> blackcells<-data.frame(lat=lat,lon=lon,pop=pop)
> plot(0,type="n",xlim=c(97.5,108.5),ylim=c(27.5,38.5),
>  xlab="Longitude",ylab="Latitude")
> abline(h=27.5)
> abline(h=lat+0.5)
> abline(v=97.5)
> abline(v=lon+0.5)
> text(blackcells$lon,blackcells$lat,pop)
> # the red cells will be centered on the corners of 4 black cells
> lat2<-rep(seq(28.5,34.5,by=2),4)
> lon2<-rep(seq(99.5,105.5,by=2),each=4)
> redcells<-data.frame(lat=lat2,lon=lon2,value=NA)
> display the red cells
> rect(lon2-1,lat2-1,lon2+1,lat2+1,border="red",lwd=2)
> nblackcells<-dim(blackcells)[1]
> nredcells<-dim(redcells)[1]
> for(redcell in 1:nredcells) {
>  close4<-rep(NA,4)
>  closen<-1
>  for(blackcell in 1:nblackcells) {
>   if(abs(blackcells[blackcell,"lat"]-redcells[redcell,"lat"]) < 1 &&
>abs(blackcells[blackcell,"lon"]-redcells[redcell,"lon"]) < 1) {
>close4[closen]<-blackcells[blackcell,"pop"]
>closen<-closen + 1
>   }
>  }
>  cat(close4,"\n")
>  redcells[redcell,"value"]<-sum(close4)/4
> }
> library(plotrix)
> boxed.labels(redcells$lon,redcells$lat,redcells$value,col="red")
>
> Jim
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to average values from grid cells with coordinates

2018-05-18 Thread lily li
Hi Jim,

Thanks. Yes, the two assumptions are correct, and they reflect the
datasets. I have an uncertainty about the code below. Why do you use
abs(blackcells[[i]]$lat - redcell$lat) <1 rather than a different number
than 1? Second, why to construct blackcells as a list, rather than a
dataframe. Because in a dataframe, each row can represent one grid cell,
while the three columns can represent the lati, lon, and pop. Thanks again
for your help.

for(i in 1:121) {
if(abs(blackcells[[i]]$lat-redcell$lat) < 1 &&
abs(blackcells[[i]]$lon-redcell$lon) < 1) {
close4[closen]<-i
closen<-closen+1
}
}


On Wed, May 16, 2018 at 2:45 AM, Jim Lemon  wrote:

> Hi lily,
> There are one or two assumptions to be made here. First is that the
> latitude and longitude values of the "black" cells are equally spaced
> as in your illustration. Second, that all latitude and longitude
> values for the "red" cells fall at the corners of four "black" cells.
>
> You can get the four "black" cells by finding the lat/lon values that
> are closest to the "red" lat/lon values. Here's a basic example:
>
> lat<-rep(28:38,11)
> lon<-rep(98:108,each=11)
> pop<-sample(80:200,121)
> blackcells<-list()
> for(i in 1:121) blackcells[[i]]<-list(lat=lat[i],lon=lon[i],pop=pop[i])
> redcell<-list(lat=33.5,lon=100.5,pop=NA)
> close4<-rep(NA,4)
> closen<-1
> for(i in 1:121) {
>  if(abs(blackcells[[i]]$lat-redcell$lat) < 1 &&
>   abs(blackcells[[i]]$lon-redcell$lon) < 1) {
>   close4[closen]<-i
>   closen<-closen+1
>  }
> }
> cat(close4,"\n")
> redcell$pop<-(blackcells[[close4[1]]]$pop +
>  blackcells[[close4[2]]]$pop + blackcells[[close4[3]]]$pop +
>  blackcells[[close4[4]]]$pop)/4
> print(blackcells[[close4[1]]])
> print(blackcells[[close4[2]]])
> print(blackcells[[close4[3]]])
> print(blackcells[[close4[4]]])
> print(redcell)
>
> As you can see, this has picked out the four "black" cells closest to
> the "red" cell's coordinates and calculated the mean.
>
> Jim
>
> On Wed, May 16, 2018 at 2:23 PM, lily li  wrote:
> > Hi R users,
> >
> > I have a question about data processing. I have such a dataset, while
> each
> > black grid cell has a few attributes and the corresponding attribute
> > values. The latitude and longitude of the center of each grid cell are
> > given also.
> >
> > Then I want to average the attribute values from four adjacent grid cells
> > to get the average value for the center of each red grid cell. Thus,
> there
> > are the same number of attributes, but different values. The red grid
> cells
> > do not overlap. I was thinking to write such a script that can ID each
> > black grid cell, for example, 1, 2, 3, 4, ..., then the corresponding
> four
> > grid cells will be used to average for the red grid cell. But I just have
> > the latitude and longitude, attribute values for the black cells, and
> also
> > latitude and longitude for the red cells, how to write such a script in
> R.
> > Could anyone give me suggestion about the work flow? Thanks very much.
> >
> > I attached the picture of the grid cells here.
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
> >
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] add single points to a level plot

2018-03-08 Thread lily li
Thanks.
Now it can run and generate plots, but there are the two lines on each of
the plots. I don't know the problem for this?

Error using packet 1
any(sp) is not TRUE



On Thu, Mar 8, 2018 at 8:48 AM, Eric Berger  wrote:

> You need to load the package 'rasterVis'
>
> > library(rasterVis)
>
> HTH,
> Eric
>
>
> On Thu, Mar 8, 2018 at 5:11 PM, lily li  wrote:
>
>> Hi all,
>>
>> I ran the code:
>> > s <- stack(replicate(2, raster(matrix(runif(100), 10
>> > xy <- data.frame(coordinates(sampleRandom(s, 10, sp=TRUE)),
>> +  z1=runif(10), z2=runif(10))
>> > levelplot(s, margin=FALSE, at=seq(0, 1, 0.05)) +
>> +   layer(sp.points(xy, pch=ifelse(pts$z1 < 0.5, 2, 3), cex=2, col=1),
>> columns=1) +
>> +   layer(sp.points(xy, pch=ifelse(pts$z2 < 0.5, 2, 3), cex=2, col=1),
>> columns=2)
>>
>> And got the error:
>> Error in UseMethod("levelplot") :
>>   no applicable method for 'levelplot' applied to an object of class
>> "c('RasterStack', 'Raster', 'RasterStackBrick', 'BasicRaster')"
>>
>> what is the problem? Thanks.
>>
>> On Thu, Mar 8, 2018 at 12:07 AM, lily li  wrote:
>>
>> > Hi all,
>> >
>> > I'm trying to add single points with known coordinates to a level plot,
>> > but could not find the proper answer. I got to know that layer()
>> function
>> > is good for this, but I don't know which package is related to this
>> > function. The source is here:
>> > https://stackoverflow.com/questions/28597149/add-xy-points-
>> to-raster-map-
>> > generated-by-levelplot
>> >
>> > but my question is a little different as I know the coordinates of the
>> > single point, rather than a range. Thanks for any help you could
>> provide.
>> >
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] add single points to a level plot

2018-03-08 Thread lily li
Hi all,

I ran the code:
> s <- stack(replicate(2, raster(matrix(runif(100), 10
> xy <- data.frame(coordinates(sampleRandom(s, 10, sp=TRUE)),
+  z1=runif(10), z2=runif(10))
> levelplot(s, margin=FALSE, at=seq(0, 1, 0.05)) +
+   layer(sp.points(xy, pch=ifelse(pts$z1 < 0.5, 2, 3), cex=2, col=1),
columns=1) +
+   layer(sp.points(xy, pch=ifelse(pts$z2 < 0.5, 2, 3), cex=2, col=1),
columns=2)

And got the error:
Error in UseMethod("levelplot") :
  no applicable method for 'levelplot' applied to an object of class
"c('RasterStack', 'Raster', 'RasterStackBrick', 'BasicRaster')"

what is the problem? Thanks.

On Thu, Mar 8, 2018 at 12:07 AM, lily li  wrote:

> Hi all,
>
> I'm trying to add single points with known coordinates to a level plot,
> but could not find the proper answer. I got to know that layer() function
> is good for this, but I don't know which package is related to this
> function. The source is here:
> https://stackoverflow.com/questions/28597149/add-xy-points-to-raster-map-
> generated-by-levelplot
>
> but my question is a little different as I know the coordinates of the
> single point, rather than a range. Thanks for any help you could provide.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] add single points to a level plot

2018-03-07 Thread lily li
Hi all,

I'm trying to add single points with known coordinates to a level plot, but
could not find the proper answer. I got to know that layer() function is
good for this, but I don't know which package is related to this function.
The source is here:
https://stackoverflow.com/questions/28597149/add-xy-points-to-raster-map-generated-by-levelplot

but my question is a little different as I know the coordinates of the
single point, rather than a range. Thanks for any help you could provide.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] error in loading rgdal package

2018-02-16 Thread lily li
Hi Loris,
Thanks. I tried to update the R software and reinstalled the GDAL library.
It works now.


On Thu, Feb 15, 2018 at 11:49 PM, Loris Bennett 
wrote:

> Hi Lily,
>
> lily li  writes:
>
> > Hi R users,
> >
> > Could you help me to see this problem? I could now load "rgdal" even
> though
> > I downloaded the compressed folder. Thanks for your help.
> >
> > Loading required package: sp
> > Error in dyn.load(file, DLLpath = DLLpath, ...) :
> >   unable to load shared object
> > '/Library/Frameworks/R.framework/Versions/3.3/
> Resources/library/rgdal/libs/rgdal.so':
>
> Have you installed the GDAL library itself?  The R package rgdal needs
> this.  See the "SystemRequirements" section on the CPAN page:
>
>   https://CRAN.R-project.org/package=rgdal
>
> Cheers,
>
> Loris
>
> --
> Dr. Loris Bennett (Mr.)
> ZEDAT, Freie Universität Berlin Email loris.benn...@fu-berlin.de
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] error in loading rgdal package

2018-02-15 Thread lily li
Hi R users,

Could you help me to see this problem? I could now load "rgdal" even though
I downloaded the compressed folder. Thanks for your help.

Loading required package: sp
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object
'/Library/Frameworks/R.framework/Versions/3.3/Resources/library/rgdal/libs/rgdal.so':

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Steps to create spatial plots

2018-01-16 Thread lily li
Hi Eric,

Thanks, it works. If I want to convert the matrix to the 1-D vector for the
levelplot, should I use the command below? I thought the t() is a reverse
function, but may be not.

values <- layer$z
values.v <- as.vector(t(values))

On Tue, Jan 16, 2018 at 12:36 AM, Eric Berger  wrote:

> If layer$z is a matrix and you want to reverse the order of the rows, you
> can do:
>
> n <- nrow(layer$z)
> layer$z <- layer$z[ n:1, ]
>
> HTH,
> Eric
>
>
> On Tue, Jan 16, 2018 at 8:43 AM, lily li  wrote:
>
>> Sorry for the emails, I just wanted to have an example.
>> layer$z
>>
>> 1  1  3  4  6  2
>> 2  3  4  1  2  9
>> 1  4  5  2  1  8
>>
>> How to convert the matrix to layer$z = c(1, 4, 5, 2, 1, 8, 2, 3, 4, 1, 2,
>> 9, 1, 1, 3, 4, 6, 2)?
>> I think this vector is the order that levelplot can use. Thanks again.
>>
>>
>> On Mon, Jan 15, 2018 at 10:58 PM, lily li  wrote:
>>
>> > Hi Bert,
>> >
>> > I think you are correct that I can use levelplot, but I have a question
>> > about converting data. For example, the statement:
>> > levelplot(Z~X*Y), Z is row-wise from the lower left corner to the upper
>> > right corner.
>> > My dataset just have gridded Z data as a txt file (or can be called
>> > matrix?), how to convert them to the vector in order for levelplot to
>> use?
>> > Thanks.
>> >
>> > On Mon, Jan 15, 2018 at 6:04 PM, Bert Gunter 
>> > wrote:
>> >
>> >> From your description, I am **guessing** that you may not want a
>> "spatial
>> >> map" (including projections) at all, but rather something like a level
>> >> plot. See ?levelplot in the lattice package for details. Both I am sure
>> >> ggplot2 has something similar.
>> >>
>> >> Apologies if I havemisunderstood your intent/specifications.
>> >>
>> >> Cheers,
>> >> Bert
>> >>
>> >>
>> >> Bert Gunter
>> >>
>> >> "The trouble with having an open mind is that people keep coming along
>> >> and sticking things into it."
>> >> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>> >>
>> >> On Mon, Jan 15, 2018 at 4:54 PM, lily li  wrote:
>> >>
>> >>> Hi Roman,
>> >>>
>> >>> Thanks for your reply. For the spatial coordinates layer, I just have
>> >>> coordinates of the upper left corner, numbers of rows and columns of
>> the
>> >>> spatial map, and grid cell size. How to create a spatial layer of
>> >>> coordinates from this data? Thanks.
>> >>>
>> >>>
>> >>> On Mon, Jan 15, 2018 at 3:26 PM, Roman Luštrik <
>> roman.lust...@gmail.com>
>> >>> wrote:
>> >>>
>> >>> > You will need to coerce your data into a "spatial" kind, as
>> >>> implemented in
>> >>> > `sp` or as of late, `sf` packages. You might want to give the
>> >>> vignettes a
>> >>> > whirl before you proceed.
>> >>> > Roughly, you will have to coerce the data to Spatial* (you could go
>> >>> for a
>> >>> > point, raster or grid type, I think) and also specify the
>> projection.
>> >>> Once
>> >>> > you have that, plotting should be handled by packages.
>> >>> >
>> >>> > Here are a few quick links that might come handy:
>> >>> >
>> >>> > https://cran.r-project.org/web/views/Spatial.html
>> >>> > http://www.datacarpentry.org/R-spatial-raster-vector-
>> >>> > lesson/10-vector-csv-to-shapefile-in-r/
>> >>> >
>> >>> >
>> >>> > Cheers,
>> >>> > Roman
>> >>> >
>> >>> > On Mon, Jan 15, 2018 at 11:22 PM, lily li 
>> wrote:
>> >>> >
>> >>> >> Hi users,
>> >>> >>
>> >>> >> I have no clear clue about plotting spatial data. For example, I
>> just
>> >>> >> have a table with attribute values of each grid cell, such as
>> >>> elevation.
>> >>> >> Then I have coordinates of the upper left corner in UTM, the number
>> >>> of rows
>> >>> >> and columns, and grid cell size. How to create spatial plot of
>> >>> elevations
>> &

Re: [R] Steps to create spatial plots

2018-01-15 Thread lily li
Sorry for the emails, I just wanted to have an example.
layer$z

1  1  3  4  6  2
2  3  4  1  2  9
1  4  5  2  1  8

How to convert the matrix to layer$z = c(1, 4, 5, 2, 1, 8, 2, 3, 4, 1, 2,
9, 1, 1, 3, 4, 6, 2)?
I think this vector is the order that levelplot can use. Thanks again.


On Mon, Jan 15, 2018 at 10:58 PM, lily li  wrote:

> Hi Bert,
>
> I think you are correct that I can use levelplot, but I have a question
> about converting data. For example, the statement:
> levelplot(Z~X*Y), Z is row-wise from the lower left corner to the upper
> right corner.
> My dataset just have gridded Z data as a txt file (or can be called
> matrix?), how to convert them to the vector in order for levelplot to use?
> Thanks.
>
> On Mon, Jan 15, 2018 at 6:04 PM, Bert Gunter 
> wrote:
>
>> From your description, I am **guessing** that you may not want a "spatial
>> map" (including projections) at all, but rather something like a level
>> plot. See ?levelplot in the lattice package for details. Both I am sure
>> ggplot2 has something similar.
>>
>> Apologies if I havemisunderstood your intent/specifications.
>>
>> Cheers,
>> Bert
>>
>>
>> Bert Gunter
>>
>> "The trouble with having an open mind is that people keep coming along
>> and sticking things into it."
>> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>>
>> On Mon, Jan 15, 2018 at 4:54 PM, lily li  wrote:
>>
>>> Hi Roman,
>>>
>>> Thanks for your reply. For the spatial coordinates layer, I just have
>>> coordinates of the upper left corner, numbers of rows and columns of the
>>> spatial map, and grid cell size. How to create a spatial layer of
>>> coordinates from this data? Thanks.
>>>
>>>
>>> On Mon, Jan 15, 2018 at 3:26 PM, Roman Luštrik 
>>> wrote:
>>>
>>> > You will need to coerce your data into a "spatial" kind, as
>>> implemented in
>>> > `sp` or as of late, `sf` packages. You might want to give the
>>> vignettes a
>>> > whirl before you proceed.
>>> > Roughly, you will have to coerce the data to Spatial* (you could go
>>> for a
>>> > point, raster or grid type, I think) and also specify the projection.
>>> Once
>>> > you have that, plotting should be handled by packages.
>>> >
>>> > Here are a few quick links that might come handy:
>>> >
>>> > https://cran.r-project.org/web/views/Spatial.html
>>> > http://www.datacarpentry.org/R-spatial-raster-vector-
>>> > lesson/10-vector-csv-to-shapefile-in-r/
>>> >
>>> >
>>> > Cheers,
>>> > Roman
>>> >
>>> > On Mon, Jan 15, 2018 at 11:22 PM, lily li  wrote:
>>> >
>>> >> Hi users,
>>> >>
>>> >> I have no clear clue about plotting spatial data. For example, I just
>>> >> have a table with attribute values of each grid cell, such as
>>> elevation.
>>> >> Then I have coordinates of the upper left corner in UTM, the number
>>> of rows
>>> >> and columns, and grid cell size. How to create spatial plot of
>>> elevations
>>> >> for the grid cells, in color ramp? Should I create a spatial grid
>>> layer
>>> >> with all the polygons first? Thanks.
>>> >>
>>> >> --
>>> >> --
>>> >> You received this message because you are subscribed to the ggplot2
>>> >> mailing list.
>>> >> Please provide a reproducible example: https://github.com/hadley/devt
>>> >> ools/wiki/Reproducibility
>>> >>
>>> >> To post: email ggpl...@googlegroups.com
>>> >> To unsubscribe: email ggplot2+unsubscr...@googlegroups.com
>>> >> More options: http://groups.google.com/group/ggplot2
>>> >>
>>> >> ---
>>> >> You received this message because you are subscribed to the Google
>>> Groups
>>> >> "ggplot2" group.
>>> >> To unsubscribe from this group and stop receiving emails from it,
>>> send an
>>> >> email to ggplot2+unsubscr...@googlegroups.com.
>>> >> For more options, visit https://groups.google.com/d/optout.
>>> >>
>>> >
>>> >
>>> >
>>> > --
>>> > In God we trust, all others bring data.
>>> >
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> __
>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> https://stat.ethz.ch/mailman/listinfo/r-help
>>> PLEASE do read the posting guide http://www.R-project.org/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Steps to create spatial plots

2018-01-15 Thread lily li
Hi Bert,

I think you are correct that I can use levelplot, but I have a question
about converting data. For example, the statement:
levelplot(Z~X*Y), Z is row-wise from the lower left corner to the upper
right corner.
My dataset just have gridded Z data as a txt file (or can be called
matrix?), how to convert them to the vector in order for levelplot to use?
Thanks.

On Mon, Jan 15, 2018 at 6:04 PM, Bert Gunter  wrote:

> From your description, I am **guessing** that you may not want a "spatial
> map" (including projections) at all, but rather something like a level
> plot. See ?levelplot in the lattice package for details. Both I am sure
> ggplot2 has something similar.
>
> Apologies if I havemisunderstood your intent/specifications.
>
> Cheers,
> Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> On Mon, Jan 15, 2018 at 4:54 PM, lily li  wrote:
>
>> Hi Roman,
>>
>> Thanks for your reply. For the spatial coordinates layer, I just have
>> coordinates of the upper left corner, numbers of rows and columns of the
>> spatial map, and grid cell size. How to create a spatial layer of
>> coordinates from this data? Thanks.
>>
>>
>> On Mon, Jan 15, 2018 at 3:26 PM, Roman Luštrik 
>> wrote:
>>
>> > You will need to coerce your data into a "spatial" kind, as implemented
>> in
>> > `sp` or as of late, `sf` packages. You might want to give the vignettes
>> a
>> > whirl before you proceed.
>> > Roughly, you will have to coerce the data to Spatial* (you could go for
>> a
>> > point, raster or grid type, I think) and also specify the projection.
>> Once
>> > you have that, plotting should be handled by packages.
>> >
>> > Here are a few quick links that might come handy:
>> >
>> > https://cran.r-project.org/web/views/Spatial.html
>> > http://www.datacarpentry.org/R-spatial-raster-vector-
>> > lesson/10-vector-csv-to-shapefile-in-r/
>> >
>> >
>> > Cheers,
>> > Roman
>> >
>> > On Mon, Jan 15, 2018 at 11:22 PM, lily li  wrote:
>> >
>> >> Hi users,
>> >>
>> >> I have no clear clue about plotting spatial data. For example, I just
>> >> have a table with attribute values of each grid cell, such as
>> elevation.
>> >> Then I have coordinates of the upper left corner in UTM, the number of
>> rows
>> >> and columns, and grid cell size. How to create spatial plot of
>> elevations
>> >> for the grid cells, in color ramp? Should I create a spatial grid layer
>> >> with all the polygons first? Thanks.
>> >>
>> >> --
>> >> --
>> >> You received this message because you are subscribed to the ggplot2
>> >> mailing list.
>> >> Please provide a reproducible example: https://github.com/hadley/devt
>> >> ools/wiki/Reproducibility
>> >>
>> >> To post: email ggpl...@googlegroups.com
>> >> To unsubscribe: email ggplot2+unsubscr...@googlegroups.com
>> >> More options: http://groups.google.com/group/ggplot2
>> >>
>> >> ---
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "ggplot2" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> an
>> >> email to ggplot2+unsubscr...@googlegroups.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >>
>> >
>> >
>> >
>> > --
>> > In God we trust, all others bring data.
>> >
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Steps to create spatial plots

2018-01-15 Thread lily li
The projection is UTM zone, but I meant that I don't have coordinates for
each grid cell, rather, I have coordinates for the upper left corner. The
attribute layer is elevation for each grid cell for example, I assume that
I need to create coordinates for the grid cells first? Thanks.

On Mon, Jan 15, 2018 at 6:04 PM, Bert Gunter  wrote:

> From your description, I am **guessing** that you may not want a "spatial
> map" (including projections) at all, but rather something like a level
> plot. See ?levelplot in the lattice package for details. Both I am sure
> ggplot2 has something similar.
>
> Apologies if I havemisunderstood your intent/specifications.
>
> Cheers,
> Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
> On Mon, Jan 15, 2018 at 4:54 PM, lily li  wrote:
>
>> Hi Roman,
>>
>> Thanks for your reply. For the spatial coordinates layer, I just have
>> coordinates of the upper left corner, numbers of rows and columns of the
>> spatial map, and grid cell size. How to create a spatial layer of
>> coordinates from this data? Thanks.
>>
>>
>> On Mon, Jan 15, 2018 at 3:26 PM, Roman Luštrik 
>> wrote:
>>
>> > You will need to coerce your data into a "spatial" kind, as implemented
>> in
>> > `sp` or as of late, `sf` packages. You might want to give the vignettes
>> a
>> > whirl before you proceed.
>> > Roughly, you will have to coerce the data to Spatial* (you could go for
>> a
>> > point, raster or grid type, I think) and also specify the projection.
>> Once
>> > you have that, plotting should be handled by packages.
>> >
>> > Here are a few quick links that might come handy:
>> >
>> > https://cran.r-project.org/web/views/Spatial.html
>> > http://www.datacarpentry.org/R-spatial-raster-vector-
>> > lesson/10-vector-csv-to-shapefile-in-r/
>> >
>> >
>> > Cheers,
>> > Roman
>> >
>> > On Mon, Jan 15, 2018 at 11:22 PM, lily li  wrote:
>> >
>> >> Hi users,
>> >>
>> >> I have no clear clue about plotting spatial data. For example, I just
>> >> have a table with attribute values of each grid cell, such as
>> elevation.
>> >> Then I have coordinates of the upper left corner in UTM, the number of
>> rows
>> >> and columns, and grid cell size. How to create spatial plot of
>> elevations
>> >> for the grid cells, in color ramp? Should I create a spatial grid layer
>> >> with all the polygons first? Thanks.
>> >>
>> >> --
>> >> --
>> >> You received this message because you are subscribed to the ggplot2
>> >> mailing list.
>> >> Please provide a reproducible example: https://github.com/hadley/devt
>> >> ools/wiki/Reproducibility
>> >>
>> >> To post: email ggpl...@googlegroups.com
>> >> To unsubscribe: email ggplot2+unsubscr...@googlegroups.com
>> >> More options: http://groups.google.com/group/ggplot2
>> >>
>> >> ---
>> >> You received this message because you are subscribed to the Google
>> Groups
>> >> "ggplot2" group.
>> >> To unsubscribe from this group and stop receiving emails from it, send
>> an
>> >> email to ggplot2+unsubscr...@googlegroups.com.
>> >> For more options, visit https://groups.google.com/d/optout.
>> >>
>> >
>> >
>> >
>> > --
>> > In God we trust, all others bring data.
>> >
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] Steps to create spatial plots

2018-01-15 Thread lily li
Hi Roman,

Thanks for your reply. For the spatial coordinates layer, I just have
coordinates of the upper left corner, numbers of rows and columns of the
spatial map, and grid cell size. How to create a spatial layer of
coordinates from this data? Thanks.


On Mon, Jan 15, 2018 at 3:26 PM, Roman Luštrik 
wrote:

> You will need to coerce your data into a "spatial" kind, as implemented in
> `sp` or as of late, `sf` packages. You might want to give the vignettes a
> whirl before you proceed.
> Roughly, you will have to coerce the data to Spatial* (you could go for a
> point, raster or grid type, I think) and also specify the projection. Once
> you have that, plotting should be handled by packages.
>
> Here are a few quick links that might come handy:
>
> https://cran.r-project.org/web/views/Spatial.html
> http://www.datacarpentry.org/R-spatial-raster-vector-
> lesson/10-vector-csv-to-shapefile-in-r/
>
>
> Cheers,
> Roman
>
> On Mon, Jan 15, 2018 at 11:22 PM, lily li  wrote:
>
>> Hi users,
>>
>> I have no clear clue about plotting spatial data. For example, I just
>> have a table with attribute values of each grid cell, such as elevation.
>> Then I have coordinates of the upper left corner in UTM, the number of rows
>> and columns, and grid cell size. How to create spatial plot of elevations
>> for the grid cells, in color ramp? Should I create a spatial grid layer
>> with all the polygons first? Thanks.
>>
>> --
>> --
>> You received this message because you are subscribed to the ggplot2
>> mailing list.
>> Please provide a reproducible example: https://github.com/hadley/devt
>> ools/wiki/Reproducibility
>>
>> To post: email ggpl...@googlegroups.com
>> To unsubscribe: email ggplot2+unsubscr...@googlegroups.com
>> More options: http://groups.google.com/group/ggplot2
>>
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "ggplot2" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to ggplot2+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> In God we trust, all others bring data.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] Steps to create spatial plots

2018-01-15 Thread lily li
Hi users,

I have no clear clue about plotting spatial data. For example, I just have
a table with attribute values of each grid cell, such as elevation. Then I
have coordinates of the upper left corner in UTM, the number of rows and
columns, and grid cell size. How to create spatial plot of elevations for
the grid cells, in color ramp? Should I create a spatial grid layer with
all the polygons first? Thanks.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Errors in reading in txt files

2017-12-15 Thread lily li
I use the method, df$Time = as.POSIXct(df$Time), but it has the warning
message:
Error in as.POSIXlt.character(x, tz, ...) :
  character string is not in a standard unambiguous format

On Thu, Dec 14, 2017 at 1:31 PM, MacQueen, Don  wrote:

> In addition to which, I would recommend
>
> df <- read.table("DATAM", header = TRUE, fill = TRUE,
> stringsAsFactors=FALSE)
>
> and then converting the Time column to POSIXct date-time values using
>   as.POSIXct()
> specifying the format using formatting codes found in
>   ?strptime
> because the times are not in the POSIXct default format.
>
>
> This example might indicate the idea:
>
> > as.POSIXct('2012-10-12 13:14')
> [1] "2012-10-12 13:14:00 PDT"
> > class(as.POSIXct('2012-10-12 13:14'))
> [1] "POSIXct" "POSIXt"
>
> -Don
>
> --
> Don MacQueen
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
> Lab cell 925-724-7509
>
>
>
> On 12/14/17, 11:01 AM, "R-help on behalf of Ista Zahn" <
> r-help-boun...@r-project.org on behalf of istaz...@gmail.com> wrote:
>
> On Thu, Dec 14, 2017 at 1:58 PM, Berend Hasselman 
> wrote:
> >
> >> On 14 Dec 2017, at 19:36, lily li  wrote:
> >>
> >> Hi R users,
> >>
> >> I have a question about reading from text files. The file has the
> structure
> >> below:
> >>
> >> TimeColumn1   Column2
> >> 01.01.2001-12:00:00
> >
> > This line does not contain 3 elements; only one.
> > You'll have to fix that line. Delete it, prepend it with a comment
> character of add enough columns.
>
> I definitely don't recommend that. Instead, read
>
> ?read.table
>
> to learn about the "fill" and "header" arguments.
>
> df = read.table("DATAM", header = TRUE, fill = TRUE)
>
> will probably work.
>
> Best,
> Ista
>
>
> >
> >
> > Berend
> >
> >> 01.01.2001-24:00:0012 11
> >> 01.02.2001-12:00:0013 10
> >> 01.02.2001-24:00:0011 12
> >> 01.03.2001-12:00:0015 11
> >> 01.03.2001-24:00:0016 10
> >> ...
> >>
> >> I just use the simple script to open it: df = read.table('DATAM',
> head=T).
> >>
> >> But it has the error and thus cannot read the file:
> >> Error in scan(file = file, what = what, sep = sep, quote = quote,
> dec =
> >> dec,  :
> >>  line 1 did not have 3 elements
> >>
> >> How to read it with three fixed columns, and how to read the time
> format in
> >> the first column correctly? Thanks for your help.
> >>
> >>   [[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Errors in reading in txt files

2017-12-14 Thread lily li
Thanks, Berend. I thought R can recognize the space automatically, such as
na.strings="", or sep=' '.

On Thu, Dec 14, 2017 at 11:58 AM, Berend Hasselman  wrote:

>
> > On 14 Dec 2017, at 19:36, lily li  wrote:
> >
> > Hi R users,
> >
> > I have a question about reading from text files. The file has the
> structure
> > below:
> >
> > TimeColumn1   Column2
> > 01.01.2001-12:00:00
>
> This line does not contain 3 elements; only one.
> You'll have to fix that line. Delete it, prepend it with a comment
> character of add enough columns.
>
>
> Berend
>
> > 01.01.2001-24:00:0012 11
> > 01.02.2001-12:00:0013 10
> > 01.02.2001-24:00:0011 12
> > 01.03.2001-12:00:0015 11
> > 01.03.2001-24:00:0016 10
> > ...
> >
> > I just use the simple script to open it: df = read.table('DATAM',
> head=T).
> >
> > But it has the error and thus cannot read the file:
> > Error in scan(file = file, what = what, sep = sep, quote = quote, dec =
> > dec,  :
> >  line 1 did not have 3 elements
> >
> > How to read it with three fixed columns, and how to read the time format
> in
> > the first column correctly? Thanks for your help.
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Errors in reading in txt files

2017-12-14 Thread lily li
Hi R users,

I have a question about reading from text files. The file has the structure
below:

TimeColumn1   Column2
01.01.2001-12:00:00
01.01.2001-24:00:0012 11
01.02.2001-12:00:0013 10
01.02.2001-24:00:0011 12
01.03.2001-12:00:0015 11
01.03.2001-24:00:0016 10
...

I just use the simple script to open it: df = read.table('DATAM', head=T).

But it has the error and thus cannot read the file:
Error in scan(file = file, what = what, sep = sep, quote = quote, dec =
dec,  :
  line 1 did not have 3 elements

How to read it with three fixed columns, and how to read the time format in
the first column correctly? Thanks for your help.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] about taylor.diagram

2017-10-10 Thread lily li
Hi R users,

I don't know if you have used taylor.diagram function. Why my diagram is
not like 1/4th of a round shape, but more flat, like 1/4th of an oval?
Thanks.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About multiple panels with limited space in-between

2017-10-10 Thread lily li
I use the code below to plot, but have some difficulties.

par(mfrow=c(2,5))
par(mar=c(2,1,1,0), oma=c(4,4,.5,.5))
plot(DF1$var1,DF1$A)
plot(DF1$var2,DF1$A, ylab=F); plot(DF1$var3,DF1$A,ylab=F);
plot(DF1$var4,DF1$A, ylab=F); plot(DF1$var5,DF1$A,ylab=F)
plot(DF2$var1,DF2$A)
plot(DF2$var2,DF2$A, ylab=F); plot(DF2$var3,DF2$A, ylab=F);
plot(DF2$var4,DF2$A, ylab=F); plot(DF2$var5,DF2$A, ylab=F)

Changing "ylab=F" to "labels=F" got the error message: "labels" is not a
graphical prameter.
For each row, I would like to use the leftmost y-axis, so the other figures
do not need to have y-axis. Then how to just have x-labels for the bottom
row, but have ticks and numbers in the x-labels for the top row? Also, I
forgot to attach the figure and here it is. This is more complicated, but I
just need two rows, and there are spaces between the two rows. Thanks first.

On Tue, Oct 10, 2017 at 2:41 PM, lily li  wrote:

> Hi R users,
>
> I have a question about plotting. The following two datasets are an
> example. What I have in mind is like the attached figure, but just have two
> rows, top row is for DF1, bottom row is for DF2. The top and bottom rows,
> have x-axis as var1, var2, var3, etc, while the y-axis represents A. For
> each row, only the leftmost panel has y-axis ticks and label. For the two
> rows, only the bottom row has x-axis ticks and label. I am not very clear
> about the coding. Thanks if you could give me any suggestions.
>
>
> DF1: Year 2000
> A var1   var2   var3   var4   var5
> 1.2   0.8 0.9 1.1 1.2 12
> 1.8   0.9 1.2 1.0 2.1 15
> 1.5   0.7 1.1 0.9 2.2 16
> 1.6   0.9 1.0 0.7 2.5 18
> ...
>
> DF2: Year 2001
> A var1   var2   var3   var4   var5
> 1.1   0.85 0.9 1.1 1.2 22
> 1.4   0.99 1.2 1.0 2.1 25
> 0.8   0.74 1.1 0.9 2.2 26
> 0.6   0.92 1.0 0.7 2.5 28
> ...
>
>
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] About multiple panels with limited space in-between

2017-10-10 Thread lily li
Hi R users,

I have a question about plotting. The following two datasets are an
example. What I have in mind is like the attached figure, but just have two
rows, top row is for DF1, bottom row is for DF2. The top and bottom rows,
have x-axis as var1, var2, var3, etc, while the y-axis represents A. For
each row, only the leftmost panel has y-axis ticks and label. For the two
rows, only the bottom row has x-axis ticks and label. I am not very clear
about the coding. Thanks if you could give me any suggestions.


DF1: Year 2000
A var1   var2   var3   var4   var5
1.2   0.8 0.9 1.1 1.2 12
1.8   0.9 1.2 1.0 2.1 15
1.5   0.7 1.1 0.9 2.2 16
1.6   0.9 1.0 0.7 2.5 18
...

DF2: Year 2001
A var1   var2   var3   var4   var5
1.1   0.85 0.9 1.1 1.2 22
1.4   0.99 1.2 1.0 2.1 25
0.8   0.74 1.1 0.9 2.2 26
0.6   0.92 1.0 0.7 2.5 28
...

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about multi-optimal points

2017-08-26 Thread lily li
Hi Ulrik,

Thanks for your suggestion, but it was not what I meant. I tried to use the
rPref package but just got a very small sample and felt clueless.

On Sat, Aug 26, 2017 at 12:37 AM, Ulrik Stervbo 
wrote:

> HI lily,
>
> for the colouring of individual points you can set the colour aesthetic.
> The ID is numeric so ggplot applies a colour scale. If we cast ID to a
> factor we get the appropriate colouring.
>
> test_df <- data.frame(ID = 1:20, v1 = rnorm(20), v2 = rnorm(20), v3 =
> rnorm(20))
>
> ggplot(data=test_df, aes(x=v1,y=v2, colour = as.factor(ID))) +
> geom_point()+ theme_bw()+
>   xlab('Variable 1')+ ylab('Variable 2')
>
> How to choose a number of samples from the dataset you can use the subset
> function to select by some variable:
> sub_test_df1 <- subset(test_df, ID < 5)
>
> ggplot(data=sub_test_df1, aes(x=v1,y=v2, colour = as.factor(ID))) +
> geom_point()+ theme_bw()+
>   xlab('Variable 1')+ ylab('Variable 2')
>
> Or sample a number of random rows using samle() if this is your intention.
> sub_test_df2 <- test_df[sample(x = 1:nrow(test_df), size = 10), ]
>
> ggplot(data=sub_test_df2, aes(x=v1,y=v2, colour = as.factor(ID))) +
> geom_point()+ theme_bw()+
>   xlab('Variable 1')+ ylab('Variable 2')
>
> HTH
> Ulrik
>
> On Fri, 25 Aug 2017 at 21:38 lily li  wrote:
>
>> Hi R users,
>>
>> I have some sets of variables and put them into one dataframe, like in the
>> following. How to choose a specific set of pareto front, such as 10 from
>> the current datasets (which contains more than 100 sets)? And how to show
>> the 10 points on one figure with different colors? I can put all the
>> points
>> on one figure though, and have the code below. I drew two ggplots to show
>> their correlations, but I want v1 and v3 to be as close as 1, v2 to be as
>> close as 0. Thanks very much.
>>
>> DF
>>
>> IDv1 v2 v3
>> 10.8 0.10.7
>> 20.85   0.30.6
>> 30.9 0.21  0.7
>> 40.95   0.22  0.8
>> 50.9 0.30.7
>> 60.8 0.40.76
>> 70.9 0.30.77
>> ...
>>
>> fig1 = ggplot(data=DF, aes(x=v1,y=v2))+ geom_point()+ theme_bw()+
>> xlab('Variable 1')+ ylab('Variable 2')
>> print(fig1)
>>
>> fig2 = ggplot(data=DF, aes(x=v1,y=v3)+ geom_point()+ theme_bw()+
>> xlab('Variable 1')+ ylab('Variable 3')
>> print(fig2)
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] about multi-optimal points

2017-08-25 Thread lily li
Hi R users,

I have some sets of variables and put them into one dataframe, like in the
following. How to choose a specific set of pareto front, such as 10 from
the current datasets (which contains more than 100 sets)? And how to show
the 10 points on one figure with different colors? I can put all the points
on one figure though, and have the code below. I drew two ggplots to show
their correlations, but I want v1 and v3 to be as close as 1, v2 to be as
close as 0. Thanks very much.

DF

IDv1 v2 v3
10.8 0.10.7
20.85   0.30.6
30.9 0.21  0.7
40.95   0.22  0.8
50.9 0.30.7
60.8 0.40.76
70.9 0.30.77
...

fig1 = ggplot(data=DF, aes(x=v1,y=v2))+ geom_point()+ theme_bw()+
xlab('Variable 1')+ ylab('Variable 2')
print(fig1)

fig2 = ggplot(data=DF, aes(x=v1,y=v3)+ geom_point()+ theme_bw()+
xlab('Variable 1')+ ylab('Variable 3')
print(fig2)

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about saving format

2017-08-05 Thread lily li
In the lower right panel of R-studio interface, there is the "Export"
button. I saved as PDF from there directly, rather than using functions

On Sat, Aug 5, 2017 at 6:18 PM, Ismail SEZEN  wrote:

>
> > On 6 Aug 2017, at 03:01, lily li  wrote:
> >
> > I am using the plot() function, but have a problem. When saving as pdf
> > format, the ‰ sign in the x-axis label becomes (...) sign. I prefer to
> save
> > in pdf, as this format has a higher resolution than jpeg or other picture
> > formats. Could anyone tell me how to do then? Thanks.
>
> Please, share minimal example. which function do you use to save the plot
> as pdf? ‘pdf' or ‘cairo_pdf’ or something else?
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] about saving format

2017-08-05 Thread lily li
Hi R users,

I am using the plot() function, but have a problem. When saving as pdf
format, the ‰ sign in the x-axis label becomes (...) sign. I prefer to save
in pdf, as this format has a higher resolution than jpeg or other picture
formats. Could anyone tell me how to do then? Thanks.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] error in installing igraph

2017-08-02 Thread lily li
Hi R users,
I got warning messages when installing the package, and I pasted the
messages below. I checked updates that my R-studio is already the newest
version. I don't know how to solve the problem. Thanks for your help.

> library(igraph)
Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object
'/Library/Frameworks/R.framework/Versions/3.2/Resources/library/igraph/libs/igraph.so':

dlopen(/Library/Frameworks/R.framework/Versions/3.2/Resources/library/igraph/libs/igraph.so,
6): Library not loaded:
/Library/Frameworks/R.framework/Versions/3.4/Resources/lib/libRlapack.dylib
  Referenced from:
/Library/Frameworks/R.framework/Versions/3.2/Resources/library/igraph/libs/igraph.so
  Reason: Incompatible library version: igraph.so requires version 3.4.0 or
later, but libRlapack.dylib provides version 3.2.0
In addition: Warning message:
package ‘igraph’ was built under R version 3.4.1
Error: package or namespace load failed for ‘igraph’

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] about installing smwrGraphs package

2017-07-23 Thread lily li
It is working now. I don't know where's the problem. thanks for your help.

On Sun, Jul 23, 2017 at 12:33 PM, peter dalgaard  wrote:

>
> > On 23 Jul 2017, at 18:31 , Uwe Ligges 
> wrote:
> >
> >
> >
> > On 23.07.2017 05:28, lily li wrote:
> >> Hi R users,
> >> I'm trying to install the package, but got the error and don't know how
> to
> >> fix it. Can anyone help me? Thanks very much.
> >> install.packages("smwrGraphs", repos=c("http://owi.usgs.gov/R",";
> >
> > I guess "http://owi.usgs.gov/R"; does not provide standard repositories
> for R?
>
> Possibly, but this seems to work for me (on a Mac):
>
> install.packages("smwrGraphs", repos=c("https://owi.usgs.gov/R";,
> CRAN="https://cloud.r-project.org";), dependencies = TRUE)
>
> Note: (a) HTTPS: (b) standard CRAN repo (cran.us does not do HTTPS??) (c)
> no newline in URL. Not sure that the named form is necessary, and things
> seem to work with plain HTTP too, but that is bad form.
>
> -pd
>
>
> >
> > Best,
> > Uwe Ligges
> >
> >
> >
> >
> >> http://cran.us.r-project.org";), dependencies = TRUE)
> >> Error in install.packages : Line starting ' ...' is malformed!
> >>  [[alternative HTML version deleted]]
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> --
> Peter Dalgaard, Professor,
> Center for Statistics, Copenhagen Business School
> Solbjerg Plads 3, 2000 Frederiksberg, Denmark
> Phone: (+45)38153501
> Office: A 4.23
> Email: pd@cbs.dk  Priv: pda...@gmail.com
>
>
>
>
>
>
>
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] about installing smwrGraphs package

2017-07-22 Thread lily li
Hi R users,

I'm trying to install the package, but got the error and don't know how to
fix it. Can anyone help me? Thanks very much.

install.packages("smwrGraphs", repos=c("http://owi.usgs.gov/R",";
http://cran.us.r-project.org";), dependencies = TRUE)

Error in install.packages : Line starting ' ...' is malformed!

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About doing figures

2017-07-16 Thread lily li
For more than 10 records, how to reformat the colors? Also, how to show the
first legend only, but at the bottom, while the second legend in your code
is not necessary? In all, the same A values have the same color, but
different symbols in DF==1 and DF==2.
Thanks for your help.

On Sun, Jul 16, 2017 at 9:28 AM, lily li  wrote:

> Hi Jim,
>
> For true color, I meant that the points in the figure do not correspond to
> the values from the dataframe. Also, why to use rainbow(9) here? And the
> legend is straight in the middle, is it possible to reformat it to the very
> bottom? Thanks again.
>
> On Sun, Jul 16, 2017 at 2:50 AM, Jim Lemon  wrote:
>
>> Hi lily,
>> As I have no idea of what the "true record" is, I can only guess.
>> Maybe this will help:
>>
>> # get some fairly distinct colors
>> rainbow_colors<-rainbow(9)
>> # this should sort the numbers in dfm$A
>> dfm$Acolor<-factor(dfm$A)
>> plot(dfm$B,dfm$C,pch=ifelse(dfm$DF==1,1,19),
>>  col=rainbow_colors[as.numeric(dfm$Acolor)])
>> legend("bottom",legend=sort(unique(dfm$A)),
>>  fill=rainbow_colors)
>> legend(25,35,c("DF=1","DF=2"),pch=c(1,19))
>>
>> Jim
>>
>>
>> On Sun, Jul 16, 2017 at 3:43 PM, lily li  wrote:
>> > Hi R users,
>> >
>> > I still have the problem about plotting. I wanted to put the datasets on
>> > one figure, x-axis represents values B, y-axis represents values C,
>> while
>> > different colors label column A. Each record uses a circle on the
>> figure,
>> > while hollow circles represent DF=1 and solid circles represent DF=2. I
>> put
>> > my code below, but the A labels do not correspond to the true record,
>> so I
>> > don't know what is the problem. Thanks for your help.
>> >
>> > dfm
>> > dfm1= subset(dfm, DF==1)
>> > dfm2= subset(dfm, DF==2)
>> > plot(c(15:30),seq(from=0,to=60,by=4),pch=19,col=NULL,xlab='Value
>> > B',ylab='Value C')
>> > Color = as.factor(dfm1$A)
>> > colordist = grDevices::colors()[grep('gr(a|e)y', grDevices::colors(),
>> > invert = T)] # for unique colors
>> > Color.unq = sample(colordist,length(Color))
>> >
>> > points(dfm1[,3],dfm1[,4],col=Color.unq,pch=1)
>> > points(dfm2[,3],dfm2[,4],col=Color.unq,pch=19)
>> > legend('bottom',as.character(Color.unq),col=Color.unq,lwd=re
>> p(2,length(Color.unq)),cex=.6,ncol=5)
>> > legend('bottom',as.character(Color),col=Color.unq,lwd=3,cex=
>> .6,ncol=5,text.width=c(9.55,9.6,9.55))
>> >
>> > dfm is the dataframe below.
>> >
>> > DF   A  B  C
>> > 1 65 21 54
>> > 1 66 23 55
>> > 1 54 24 56
>> > 1 44 23 53
>> > 1 67 22 52
>> > 1 66 21 50
>> > 1 45 20 51
>> > 1 56 19 57
>> > 1 40 25 58
>> > 1 39 24 53
>> > 2 65 25 52
>> > 2 66 20 50
>> > 2 54 21 48
>> > 2 44 30 49
>> > 2 67 27 50
>> > 2 66 20 30
>> > 2 45 25 56
>> > 2 56 14 51
>> > 2 40 29 48
>> > 2 39 29 23
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About doing figures

2017-07-16 Thread lily li
Hi Jim,

For true color, I meant that the points in the figure do not correspond to
the values from the dataframe. Also, why to use rainbow(9) here? And the
legend is straight in the middle, is it possible to reformat it to the very
bottom? Thanks again.

On Sun, Jul 16, 2017 at 2:50 AM, Jim Lemon  wrote:

> Hi lily,
> As I have no idea of what the "true record" is, I can only guess.
> Maybe this will help:
>
> # get some fairly distinct colors
> rainbow_colors<-rainbow(9)
> # this should sort the numbers in dfm$A
> dfm$Acolor<-factor(dfm$A)
> plot(dfm$B,dfm$C,pch=ifelse(dfm$DF==1,1,19),
>  col=rainbow_colors[as.numeric(dfm$Acolor)])
> legend("bottom",legend=sort(unique(dfm$A)),
>  fill=rainbow_colors)
> legend(25,35,c("DF=1","DF=2"),pch=c(1,19))
>
> Jim
>
>
> On Sun, Jul 16, 2017 at 3:43 PM, lily li  wrote:
> > Hi R users,
> >
> > I still have the problem about plotting. I wanted to put the datasets on
> > one figure, x-axis represents values B, y-axis represents values C, while
> > different colors label column A. Each record uses a circle on the figure,
> > while hollow circles represent DF=1 and solid circles represent DF=2. I
> put
> > my code below, but the A labels do not correspond to the true record, so
> I
> > don't know what is the problem. Thanks for your help.
> >
> > dfm
> > dfm1= subset(dfm, DF==1)
> > dfm2= subset(dfm, DF==2)
> > plot(c(15:30),seq(from=0,to=60,by=4),pch=19,col=NULL,xlab='Value
> > B',ylab='Value C')
> > Color = as.factor(dfm1$A)
> > colordist = grDevices::colors()[grep('gr(a|e)y', grDevices::colors(),
> > invert = T)] # for unique colors
> > Color.unq = sample(colordist,length(Color))
> >
> > points(dfm1[,3],dfm1[,4],col=Color.unq,pch=1)
> > points(dfm2[,3],dfm2[,4],col=Color.unq,pch=19)
> > legend('bottom',as.character(Color.unq),col=Color.unq,lwd=
> rep(2,length(Color.unq)),cex=.6,ncol=5)
> > legend('bottom',as.character(Color),col=Color.unq,lwd=3,
> cex=.6,ncol=5,text.width=c(9.55,9.6,9.55))
> >
> > dfm is the dataframe below.
> >
> > DF   A  B  C
> > 1 65 21 54
> > 1 66 23 55
> > 1 54 24 56
> > 1 44 23 53
> > 1 67 22 52
> > 1 66 21 50
> > 1 45 20 51
> > 1 56 19 57
> > 1 40 25 58
> > 1 39 24 53
> > 2 65 25 52
> > 2 66 20 50
> > 2 54 21 48
> > 2 44 30 49
> > 2 67 27 50
> > 2 66 20 30
> > 2 45 25 56
> > 2 56 14 51
> > 2 40 29 48
> > 2 39 29 23
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] About doing figures

2017-07-15 Thread lily li
Hi R users,

I still have the problem about plotting. I wanted to put the datasets on
one figure, x-axis represents values B, y-axis represents values C, while
different colors label column A. Each record uses a circle on the figure,
while hollow circles represent DF=1 and solid circles represent DF=2. I put
my code below, but the A labels do not correspond to the true record, so I
don't know what is the problem. Thanks for your help.

dfm
dfm1= subset(dfm, DF==1)
dfm2= subset(dfm, DF==2)
plot(c(15:30),seq(from=0,to=60,by=4),pch=19,col=NULL,xlab='Value
B',ylab='Value C')
Color = as.factor(dfm1$A)
colordist = grDevices::colors()[grep('gr(a|e)y', grDevices::colors(),
invert = T)] # for unique colors
Color.unq = sample(colordist,length(Color))

points(dfm1[,3],dfm1[,4],col=Color.unq,pch=1)
points(dfm2[,3],dfm2[,4],col=Color.unq,pch=19)
legend('bottom',as.character(Color.unq),col=Color.unq,lwd=rep(2,length(Color.unq)),cex=.6,ncol=5)
legend('bottom',as.character(Color),col=Color.unq,lwd=3,cex=.6,ncol=5,text.width=c(9.55,9.6,9.55))

dfm is the dataframe below.

DF   A  B  C
1 65 21 54
1 66 23 55
1 54 24 56
1 44 23 53
1 67 22 52
1 66 21 50
1 45 20 51
1 56 19 57
1 40 25 58
1 39 24 53
2 65 25 52
2 66 20 50
2 54 21 48
2 44 30 49
2 67 27 50
2 66 20 30
2 45 25 56
2 56 14 51
2 40 29 48
2 39 29 23

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about plotting a special case

2017-07-12 Thread lily li
Thanks, Jim. The code works, but I don't understand why you use q1090 <-
quantile(DF1$B, probs=c()), rather than DF1$A? Also, how to add a legend
for both points DF1 and DF2?

On Wed, Jul 12, 2017 at 8:25 PM, Jim Lemon  wrote:

> Hi lily,
> Here is the first plot:
>
> plot(DF1$A,DF1$B,pch=19,col="red")
> meanA<-mean(DF1$A)
> meanB<-mean(DF1$B)
> points(meanA,meanB,pch=18,col="red")
> q1090<-quantile(DF1$B,probs=c(0.1,0.9))
> library(plotrix)
> dispersion(meanA,meanB,q1090[2],q1090[1],
>  intervals=FALSE,col="red")
>
> The same code will work for a second data frame, except that you would
> use "points" instead of "plot" and change the color. You may also have
> to specify xlim and ylim in the first call to "plot" so that all
> values are on the plot.
>
> Jim
>
>
>
> On Thu, Jul 13, 2017 at 11:46 AM, lily li  wrote:
> > Hi R users,
> >
> > I have a question about plotting. There is the dataframe below, while
> each
> > row represents a record. If I want to plot on a A-B plot, i.e., x-axis
> > represents A, while y-axis represents B values. However, I want to plot
> the
> > mean value from records 1-10 as one point, while the 10th and 90th
> > percentiles represent the error bars, such as one point in the attached
> > example. I don't know how to do this, and then add a legend.
> > After the above step, if I have a dataframe DF2 with the same structure
> but
> > different values than DF1, how to show the point on the same figure, but
> > use different colors or symbols? Thanks for any advices.
> >
> > DF1
> >
> > A  B  C
> > 1 65 21 54
> > 2 66 23 55
> > 3 54 24 56
> > 4 44 23 53
> > 5 67 22 52
> > 6 66 21 50
> > 7 45 20 51
> > 8 56 19 57
> > 9 40 25 58
> > 10   39 24 53
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] about plotting a special case

2017-07-12 Thread lily li
Hi R users,

I have a question about plotting. There is the dataframe below, while each
row represents a record. If I want to plot on a A-B plot, i.e., x-axis
represents A, while y-axis represents B values. However, I want to plot the
mean value from records 1-10 as one point, while the 10th and 90th
percentiles represent the error bars, such as one point in the attached
example. I don't know how to do this, and then add a legend.
After the above step, if I have a dataframe DF2 with the same structure but
different values than DF1, how to show the point on the same figure, but
use different colors or symbols? Thanks for any advices.

DF1

A  B  C
1 65 21 54
2 66 23 55
3 54 24 56
4 44 23 53
5 67 22 52
6 66 21 50
7 45 20 51
8 56 19 57
9 40 25 58
10   39 24 53


sample.pdf
Description: Adobe PDF document
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] about adding a column for water year

2017-07-04 Thread lily li
Thanks, it works. Yes, I got the same error message when tried my original
code and Rui's code:
 In if (DF$year == i & DF$month %in% 1:9) { ... :
  the condition has length > 1 and only the first element will be used

Also, I think I made a mistake, it should be i+1 rather than i-1.
Otherwise, it has no problem.

On Tue, Jul 4, 2017 at 1:20 PM, Bert Gunter  wrote:

> Well, let's see:
>
> 1) You do not appear to understand basic flow control statements in R.
>
> Note that (from ?if):
>
> if(cond) expr
> if(cond) cons.expr  else  alt.expr
>
> where
> "cond   A length-one logical vector that is not NA."
>
> Your cond is a vector of length nrow(DF), so you don't want if, you
> want ifelse().
> Did you fail to show us your warning messages??
>
> 2. Revising your code and eliminating the extraneous brackets, one gets:
>
> for(i in 1972:1985){
>ifelse(DF$year==i & DF$month %in% 1:9, DF$wyear <- i,
>DF$wyear < i-1)
> }
>
> But that doesn't work either, giving only 1985. Why? -- because the
> assignment statement DF$wyear <- i  assigns the single value i to the
> whole column. So the whole column gets the last value of 1985, which
> is presumably what you saw but neglected to tell us.
>
> 3.  That can be fixed by ditching the loop and ising ifelse() properly:
>
> DF$wyear <-ifelse(DF$month %in% 1:9,DF$year ,DF$year-1)
>
> or even more succinctly, albeit with a trick (automatic coercion of
> logical to numeric)
>
>  DF$wyear <- DF$year - (DF$month %in% 10:12)
>
>
> This is an example of vectorization, a powerful feature of R that
> would be worthwhile for you to learn. Your initial use of a C like
> for() loop should be avoided when possible, as it could be here.
>
> If I have made an error in understanding what you are doing, please do
> let us all know. I get it wrong from time to time.
>
> Cheers,
> Bert
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, Jul 4, 2017 at 11:31 AM, lily li  wrote:
> > Hi R users,
> > I have a question about adding a column for water year. The dataframe has
> > the structure below. But the wyear column just shows one year. Could
> anyone
> > help me with this problem? Thanks.
> >
> > DF
> > year   month   day  timeflow
> > 1972  1 11972-01-01   5
> > 1972  1 21972-01-02   5.5
> > 1972  1 31972-01-03   6
> > ...
> > 1985 12   31   1985-12-31   6
> >
> >
> > for(i in 1972:1985){
> > if(DF$year==i & DF$month %in% 1:9){
> >   DF$wyear <- i {
> > }else{
> >   DF$wyear < i-1
> > }
> >   }
> > }
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] about adding a column for water year

2017-07-04 Thread lily li
Hi R users,
I have a question about adding a column for water year. The dataframe has
the structure below. But the wyear column just shows one year. Could anyone
help me with this problem? Thanks.

DF
year   month   day  timeflow
1972  1 11972-01-01   5
1972  1 21972-01-02   5.5
1972  1 31972-01-03   6
...
1985 12   31   1985-12-31   6


for(i in 1972:1985){
if(DF$year==i & DF$month %in% 1:9){
  DF$wyear <- i {
}else{
  DF$wyear < i-1
}
  }
}

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about reading files in order

2017-06-30 Thread lily li
Who is this person and what did he/she mean?

On Fri, Jun 30, 2017 at 1:48 AM, Kindell Young  wrote:

>
> On Jun 29, Silly FAGGOTS DICKS [R] 4 chicks not 18-40 year old dudes with
> no life or reason too still live except wasting our worlds oxygen on
> pathetic excuses of nothings that should eat a bullet for their next meal
> instead of bull SHIT ( although I know they like the taste of shit)  (its a
> favorite of ]r[ist subscribers )
>
> Show quoted text
>
> 15:04, "lily li"  wrote:
> >
> > Hi R users,
> > I have a question about opening the txt files and putting them into a
> > matrix. The txt files are in the folder01, while they have the name
> > file.1.txt, file.2.txt, file.3.txt, etc. There are about 200 such text
> > files. Each txt file contains one value inside. When I tried to use the
> > code below, I found that the txt files are not in order, from 1, 2, 3, to
> > 200. Rather, they are in the order 1, 10, 100, 101, etc. How to change it
> > so that they are in order? Thanks for your help.
> >
> > temp <- list.files('folder01',pattern="*.txt"
> > name.list <-lapply(paste('folder01',temp,sep='/'),read.table,head=F)
> > library(data.table)
> > files.matrix <-rbindlist(name.list)
> >
> > Also, when use the code below, how to complete it so that the values of
> the
> > files are stored in a matrix?
> > lists = list.files('folder01')
> > for (i in 1:length(lists)){
> >   file <- read.table(paste('folder01',lists[i],sep='/'),head=F)
> >   print(file)
> > }
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about reading files in order

2017-06-29 Thread lily li
Thanks also.

On Thu, Jun 29, 2017 at 2:12 PM, Adams, Jean  wrote:

> Thanks for that answer.
> I was not aware of gtools::mixedsort
> <https://www.rdocumentation.org/packages/gtools/versions/3.5.0/topics/mixedsort>
> function.
>
> Jean
>
> On Thu, Jun 29, 2017 at 2:47 PM, Henrik Bengtsson <
> henrik.bengts...@gmail.com> wrote:
>
>> You can use:
>>
>> > files <- list.files(path = "folder01")
>> > files <- gtools::mixedsort(files)
>>
>> to order the files in a "human-friendly" order rather than
>> lexicographic order (which sort() provides).
>>
>> FYI 1; it's preferred to use file.path("folder01", list[i]) rather
>> than paste('folder01',lists[i],sep='/').
>>
>> FYI 2; if you use list.files(path = "folder01", full.names = TRUE),
>> you get the full paths rather name just the file names, i.e. you don't
>> have to use file.path().
>>
>> /Henrik
>>
>> On Thu, Jun 29, 2017 at 12:04 PM, lily li  wrote:
>> > Hi R users,
>> > I have a question about opening the txt files and putting them into a
>> > matrix. The txt files are in the folder01, while they have the name
>> > file.1.txt, file.2.txt, file.3.txt, etc. There are about 200 such text
>> > files. Each txt file contains one value inside. When I tried to use the
>> > code below, I found that the txt files are not in order, from 1, 2, 3,
>> to
>> > 200. Rather, they are in the order 1, 10, 100, 101, etc. How to change
>> it
>> > so that they are in order? Thanks for your help.
>> >
>> > temp <- list.files('folder01',pattern="*.txt"
>> > name.list <-lapply(paste('folder01',temp,sep='/'),read.table,head=F)
>> > library(data.table)
>> > files.matrix <-rbindlist(name.list)
>> >
>> > Also, when use the code below, how to complete it so that the values of
>> the
>> > files are stored in a matrix?
>> > lists = list.files('folder01')
>> > for (i in 1:length(lists)){
>> >   file <- read.table(paste('folder01',lists[i],sep='/'),head=F)
>> >   print(file)
>> > }
>> >
>> > [[alternative HTML version deleted]]
>> >
>> > __
>> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> > https://stat.ethz.ch/mailman/listinfo/r-help
>> > PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> > and provide commented, minimal, self-contained, reproducible code.
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] about reading files in order

2017-06-29 Thread lily li
Hi R users,
I have a question about opening the txt files and putting them into a
matrix. The txt files are in the folder01, while they have the name
file.1.txt, file.2.txt, file.3.txt, etc. There are about 200 such text
files. Each txt file contains one value inside. When I tried to use the
code below, I found that the txt files are not in order, from 1, 2, 3, to
200. Rather, they are in the order 1, 10, 100, 101, etc. How to change it
so that they are in order? Thanks for your help.

temp <- list.files('folder01',pattern="*.txt"
name.list <-lapply(paste('folder01',temp,sep='/'),read.table,head=F)
library(data.table)
files.matrix <-rbindlist(name.list)

Also, when use the code below, how to complete it so that the values of the
files are stored in a matrix?
lists = list.files('folder01')
for (i in 1:length(lists)){
  file <- read.table(paste('folder01',lists[i],sep='/'),head=F)
  print(file)
}

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] fitting cosine curve

2017-06-20 Thread lily li
I'm trying the different parameters, but don't know what the error is:
Error in nlsModel(formula, mf, start, wts) :
  singular gradient matrix at initial parameter estimates

Thanks for any suggestions.

On Tue, Jun 20, 2017 at 7:37 PM, Don Cohen 
wrote:

>
> If you know the period and want to fit phase and amplitude, this is
> equivalent to fitting a * sin + b * cos
>
>  > >>> > I don't know how to set the approximate starting values.
>
> I'm not sure what you meant by that, but I suspect it's related to
> phase and amplitude.
>
>  > >>> > Besides, does the method work for sine curve as well?
>
> sin is the same as cos with a different phase
> Any combination of a and b above = c * sin (theta + d) for
> some value of c and d and = e * cos (theta + f) for some value
> of e and f.
> Also for any c,d and for any e,f there is an a,b.
> the c and e are what I'm calling amplitude, the d and f are what
> I'm calling phase.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] fitting cosine curve

2017-06-20 Thread lily li
Thanks. I will do a trial first. Also, is it okay to have the datasets that
have only part of the cycle, or better to have equal or more than one
cycle? That is to say, I cannot have the complete datasets sometimes.

On Tue, Jun 20, 2017 at 7:37 PM, Don Cohen 
wrote:

>
> If you know the period and want to fit phase and amplitude, this is
> equivalent to fitting a * sin + b * cos
>
>  > >>> > I don't know how to set the approximate starting values.
>
> I'm not sure what you meant by that, but I suspect it's related to
> phase and amplitude.
>
>  > >>> > Besides, does the method work for sine curve as well?
>
> sin is the same as cos with a different phase
> Any combination of a and b above = c * sin (theta + d) for
> some value of c and d and = e * cos (theta + f) for some value
> of e and f.
> Also for any c,d and for any e,f there is an a,b.
> the c and e are what I'm calling amplitude, the d and f are what
> I'm calling phase.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] fitting cosine curve

2017-06-20 Thread lily li
Thanks, that is cool. But would there be a way that can approximate the
curve by trying more starting values automatically?

On Tue, Jun 20, 2017 at 5:45 PM, Jim Lemon  wrote:

> Hi lily,
> You can get fairly good starting values just by eyeballing the curves:
>
> plot(y)
> lines(supsmu(1:20,y))
> lines(0.6*cos((1:20)/3+0.6*pi)+17.2)
>
> Jim
>
>
> On Wed, Jun 21, 2017 at 9:17 AM, lily li  wrote:
> > Hi R users,
> >
> > I have a question about fitting a cosine curve. I don't know how to set
> the
> > approximate starting values. Besides, does the method work for sine curve
> > as well? Thanks.
> >
> > Part of the dataset is in the following:
> > y=c(16.82, 16.72, 16.63, 16.47, 16.84, 16.25, 16.15, 16.83, 17.41, 17.67,
> > 17.62, 17.81, 17.91, 17.85, 17.70, 17.67, 17.45, 17.58, 16.99, 17.10)
> > t=c(7,  37,  58,  79,  96, 110, 114, 127, 146, 156, 161, 169, 176, 182,
> > 190, 197, 209, 218, 232, 240)
> >
> > I use the method to fit a curve, but it is different from the real curve,
> > which can be seen in the figure.
> > linFit  <- lm(y ~ cos(t))
> > fullFit <- nls(y ~ A*cos(omega*t+C) + B,
> > start=list(A=coef(linFit)[1],B=coef(linFit)[2],C=0,omega=.4)) #omega
> cannot
> > be set to 1, don't know why.
> > co <- coef(fullFit)
> > fit <- function(x, a, b, c, d) {a*cos(b*x+c)+d}
> > plot(x=t, y=y)
> > curve(fit(x, a=co['A'], b=co['omega'], c=co['C'],d=co['B']), add=TRUE
> > ,lwd=2, col="steelblue")
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] fitting cosine curve

2017-06-20 Thread lily li
Hi R users,

I have a question about fitting a cosine curve. I don't know how to set the
approximate starting values. Besides, does the method work for sine curve
as well? Thanks.

Part of the dataset is in the following:
y=c(16.82, 16.72, 16.63, 16.47, 16.84, 16.25, 16.15, 16.83, 17.41, 17.67,
17.62, 17.81, 17.91, 17.85, 17.70, 17.67, 17.45, 17.58, 16.99, 17.10)
t=c(7,  37,  58,  79,  96, 110, 114, 127, 146, 156, 161, 169, 176, 182,
190, 197, 209, 218, 232, 240)

I use the method to fit a curve, but it is different from the real curve,
which can be seen in the figure.
linFit  <- lm(y ~ cos(t))
fullFit <- nls(y ~ A*cos(omega*t+C) + B,
start=list(A=coef(linFit)[1],B=coef(linFit)[2],C=0,omega=.4)) #omega cannot
be set to 1, don't know why.
co <- coef(fullFit)
fit <- function(x, a, b, c, d) {a*cos(b*x+c)+d}
plot(x=t, y=y)
curve(fit(x, a=co['A'], b=co['omega'], c=co['C'],d=co['B']), add=TRUE
,lwd=2, col="steelblue")


curve1.pdf
Description: Adobe PDF document
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] [FORGED] About error bars on barplots

2017-06-17 Thread lily li
Okay, thanks for letting me know. I found the plot from website so thought
there may be a way. I just converted the format of the figure, and
attached. But I don't mean to use it as you suggested. Thanks.

On Sat, Jun 17, 2017 at 6:30 PM, Rolf Turner 
wrote:

> On 18/06/17 12:10, lily li wrote:
>
>> Hi R users,
>>
>> I have a question about adding uncertainty bars to stacked bar plots.
>>
>> DF:
>>year   A   B   C   Amin  Amax  Bmin  Bmax  Cmin  Cmax
>>   2009  40  45  15   30  61   23   56  14   17
>>   2010  36  41  23   26  54   22   51  22   24
>>
>> I use the code below:
>>
>> DF.refm = melt(subset(DF[,c(1:4)]),id.vars='year',variable_name='Legend')
>>
>> fig1 = ggplot(data=DF.refm, aes(x=year,y=value,fill=Legend))+
>>geom_bar(stat='identity',size=.5)+ theme_bw()+ xlab('Year')+
>> ylab('Percent (%)')
>> print(fig1)
>>
>> But I don't know how to change it a little bit. For example, how to add
>> the
>> error bars on the plot, as is shown in the figure below? The error bar for
>> variable A ranges from Amin to Amax, the same applies to variables B and
>> C.
>> Thanks for your help.
>>
>
>
> Your figure did not come through, at least not to me.  You are probably
> doing something fancy, and the mailing list software stripped out the
> figure.  *Do* learn to keep things simple.  _Attach_ figures as *.pdf
> files, for instance.
>
> That being said, to answer your question, my advice (and that of many
> others) is: DON'T.  Error bars on boxplots (such plots are sometimes known
> as "dynamite plots" or "detonator plots") are considered by the cognoscenti
> to be abominations.
>
> cheers,
>
> Rolf
>
> --
> Technical Editor ANZJS
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>


sample.pdf
Description: Adobe PDF document
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] About error bars on barplots

2017-06-17 Thread lily li
Hi R users,

I have a question about adding uncertainty bars to stacked bar plots.

DF:
  year   A   B   C   Amin  Amax  Bmin  Bmax  Cmin  Cmax
 2009  40  45  15   30  61   23   56  14   17
 2010  36  41  23   26  54   22   51  22   24

I use the code below:

DF.refm = melt(subset(DF[,c(1:4)]),id.vars='year',variable_name='Legend')

fig1 = ggplot(data=DF.refm, aes(x=year,y=value,fill=Legend))+
  geom_bar(stat='identity',size=.5)+ theme_bw()+ xlab('Year')+
ylab('Percent (%)')
print(fig1)

But I don't know how to change it a little bit. For example, how to add the
error bars on the plot, as is shown in the figure below? The error bar for
variable A ranges from Amin to Amax, the same applies to variables B and C.
Thanks for your help.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about fitting a regression line

2017-06-15 Thread lily li
Thanks for your replies. I tried the regression, but then got a NA value
for the slope. And here is the error message:
Coefficients: (1 not defined because of singularities)


On Thu, Jun 15, 2017 at 12:20 AM, PIKAL Petr  wrote:

> Hi
>
> But X can be some function like - sin, cos, log, exp...
>
> Cheers
> Petr
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
> > Sent: Thursday, June 15, 2017 1:28 AM
> > To: MacQueen, Don 
> > Cc: R mailing list 
> > Subject: Re: [R] about fitting a regression line
> >
> > Thanks. I thought lm() function is for linear model, such as the
> correlation
> > below:
> > Y= aX + b
> >
> > On Wed, Jun 14, 2017 at 5:25 PM, MacQueen, Don 
> > wrote:
> >
> > > Start with the lm() function; i.e., see
> > >
> > >   ?lm
> > >
> > > -Don
> > >
> > > --
> > > Don MacQueen
> > >
> > > Lawrence Livermore National Laboratory
> > > 7000 East Ave., L-627
> > > Livermore, CA 94550
> > > 925-423-1062
> > >
> > >
> > > On 6/14/17, 3:40 PM, "R-help on behalf of lily li" <
> > > r-help-boun...@r-project.org on behalf of chocol...@gmail.com> wrote:
> > >
> > > Hi R users,
> > >
> > > I have some data points (Xi, Yi), and they may follow such a
> > > pattern Yi =
> > > cCOS(Xi) + d, how to find the c and d in R? which function to use?
> > > Also,
> > > how to get the R2 and p value for this correlation? Thanks for any
> > > kind of
> > > help.
> > >
> > > [[alternative HTML version deleted]]
> > >
> > > __
> > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > > https://stat.ethz.ch/mailman/listinfo/r-help
> > > PLEASE do read the posting guide http://www.R-project.org/
> > > posting-guide.html
> > > and provide commented, minimal, self-contained, reproducible code.
> > >
> > >
> > >
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> 
> Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou
> určeny pouze jeho adresátům.
> Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě
> neprodleně jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie
> vymažte ze svého systému.
> Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email
> jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
> Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi
> či zpožděním přenosu e-mailu.
>
> V případě, že je tento e-mail součástí obchodního jednání:
> - vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření
> smlouvy, a to z jakéhokoliv důvodu i bez uvedení důvodu.
> - a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout;
> Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany
> příjemce s dodatkem či odchylkou.
> - trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve
> výslovným dosažením shody na všech jejích náležitostech.
> - odesílatel tohoto emailu informuje, že není oprávněn uzavírat za
> společnost žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn
> nebo písemně pověřen a takové pověření nebo plná moc byly adresátovi tohoto
> emailu případně osobě, kterou adresát zastupuje, předloženy nebo jejich
> existence je adresátovi či osobě jím zastoupené známá.
>
> This e-mail and any documents attached to it may be confidential and are
> intended only for its intended recipients.
> If you received this e-mail by mistake, please immediately inform its
> sender. Delete the contents of this e-mail with all attachments and its
> copies from your system.
> If you are not the intended recipient of this e-mail, you are not
> authorized to use, disseminate, copy or disclose this e-mail in any manner.
> The sender of this e-mail shall not be liable for any possible damage
> caused by modifications of the e-mail or by delay with transfer of the
> email.
>
> In case that this e-mail forms part of business dealings:
> - the

Re: [R] about fitting a regression line

2017-06-14 Thread lily li
Thanks. I thought lm() function is for linear model, such as the
correlation below:
Y= aX + b

On Wed, Jun 14, 2017 at 5:25 PM, MacQueen, Don  wrote:

> Start with the lm() function; i.e., see
>
>   ?lm
>
> -Don
>
> --
> Don MacQueen
>
> Lawrence Livermore National Laboratory
> 7000 East Ave., L-627
> Livermore, CA 94550
> 925-423-1062
>
>
> On 6/14/17, 3:40 PM, "R-help on behalf of lily li" <
> r-help-boun...@r-project.org on behalf of chocol...@gmail.com> wrote:
>
> Hi R users,
>
> I have some data points (Xi, Yi), and they may follow such a pattern
> Yi =
> cCOS(Xi) + d, how to find the c and d in R? which function to use?
> Also,
> how to get the R2 and p value for this correlation? Thanks for any
> kind of
> help.
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] about fitting a regression line

2017-06-14 Thread lily li
Hi R users,

I have some data points (Xi, Yi), and they may follow such a pattern Yi =
cCOS(Xi) + d, how to find the c and d in R? which function to use? Also,
how to get the R2 and p value for this correlation? Thanks for any kind of
help.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about combining two dataframes

2017-05-24 Thread lily li
Thanks, I didn't know the email function before.
The code works. I found that using "=" is different from using "<-".


On Wed, May 24, 2017 at 11:41 AM, David L Carlson  wrote:

> Is there a reason not to just rename the columns?
>
> First, you should use dput(DF1) and dput(DF2) to send your example tables
> to the list:
>
> DF1 <- structure(list(year = c(1981L, 1981L, 1981L, 1981L), month = c(1L,
> 1L, 1L, 1L), day = 1:4, product1 = c(18L, 19L, 16L, 19L), product2 = c(56L,
> 45L, 48L, 50L), product3 = c(20L, 22L, 28L, 21L)), .Names = c("year",
> "month", "day", "product1", "product2", "product3"), class = "data.frame",
> row.names = c(NA, -4L))
>
> DF2 <- structure(list(yr = c(1981L, 1981L, 1981L), mon = c(2L, 2L, 2L
> ), d = 1:3, prod = c(17L, 20L, 21L), prod2 = c(49L, 47L, 52L),
> prod3 = c(25L, 23L, 27L)), .Names = c("yr", "mon", "d", "prod",
> "prod2", "prod3"), class = "data.frame", row.names = c(NA, -3L
> ))
>
> Assuming they are the same structure as you said:
>
> colnames(DF2) <- colnames(DF1)
> rbind(DF1, DF2)
> #   year month day product1 product2 product3
> # 1 1981 1   1   18   56   20
> # 2 1981 1   2   19   45   22
> # 3 1981 1   3   16   48   28
> # 4 1981 1   4   19   50   21
> # 5 1981 2   1   17   49   25
> # 6 1981 2   2   20   47   23
> # 7 1981 2   3   21   52   27
>
> The attached .png image file shows you how to send plain text emails to
> r-help using gmail.
>
> -
> David L Carlson
> Department of Anthropology
> Texas A&M University
> College Station, TX 77840-4352
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
> Sent: Wednesday, May 24, 2017 12:30 PM
> To: R mailing list 
> Subject: [R] about combining two dataframes
>
> Hi all,
>
> I have a question about combining two data frames. For example, there are
> the two dataframes below, with the same structure but different column
> names and column lengths. How to add the values in DF2 to the end of DF1,
> though the column names do not match? How to add more than two? Thanks.
>
> DF1
> year   month   day   product1   product2   product3
> 1981 1  1 18  5620
> 1981 1  2 19  4522
> 1981 1  3 16  4828
> 1981 1  4 19  5021
>
> DF2
> yr mon  d prodprod2   prod3
> 1981 2  1 17  4925
> 1981 2  2 20  4723
> 1981 2  3 21  5227
>
> I use the code below but it does not work.
> require(dplyr)
> bind_rows(DF1, DF2) or bind_cols(DF1, DF2)
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about combining two dataframes

2017-05-24 Thread lily li
Thanks for your reply. I created the two dataframes (just numbers from txt
files) in one for loop, so that it is confused to give them the same column
names. That is the reason that I give them different column names to
differentiate them, but it causes difficulty in later combining them.


On Wed, May 24, 2017 at 11:42 AM, Ulrik Stervbo 
wrote:

> Hi Lily,
>
> maybe you should read up on what bind_rows/bind_cols (or the base
> functions rbind and cbind) do.
>
> bind_cols and cbind will fail in this case because of the different number
> of rows.
>
> bind_rows and rbind will fail because the column names are different - how
> can R know that month and mon really is the same.
>
> Depending on what you want, you should unify the column names (I have a
> hunch that this is what you want), or make sure the data.frames have the
> same number of rows.
>
> HTH
> Ulrik
>
>
>
> On Wed, 24 May 2017 at 19:30 lily li  wrote:
>
>> Hi all,
>>
>> I have a question about combining two data frames. For example, there are
>> the two dataframes below, with the same structure but different column
>> names and column lengths. How to add the values in DF2 to the end of DF1,
>> though the column names do not match? How to add more than two? Thanks.
>>
>> DF1
>> year   month   day   product1   product2   product3
>> 1981 1  1 18  5620
>> 1981 1  2 19  4522
>> 1981 1  3 16  4828
>> 1981 1  4 19  5021
>>
>> DF2
>> yr mon  d prodprod2   prod3
>> 1981 2  1 17  4925
>> 1981 2  2 20  4723
>> 1981 2  3 21  5227
>>
>> I use the code below but it does not work.
>> require(dplyr)
>> bind_rows(DF1, DF2) or bind_cols(DF1, DF2)
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/
>> posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] about combining two dataframes

2017-05-24 Thread lily li
Hi all,

I have a question about combining two data frames. For example, there are
the two dataframes below, with the same structure but different column
names and column lengths. How to add the values in DF2 to the end of DF1,
though the column names do not match? How to add more than two? Thanks.

DF1
year   month   day   product1   product2   product3
1981 1  1 18  5620
1981 1  2 19  4522
1981 1  3 16  4828
1981 1  4 19  5021

DF2
yr mon  d prodprod2   prod3
1981 2  1 17  4925
1981 2  2 20  4723
1981 2  3 21  5227

I use the code below but it does not work.
require(dplyr)
bind_rows(DF1, DF2) or bind_cols(DF1, DF2)

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About change columns and specific rows in R

2017-05-23 Thread lily li
Thanks for all your help. It works now.

On Tue, May 23, 2017 at 1:34 AM, William Michels via R-help <
r-help@r-project.org> wrote:

> Hi Ivan,
>
> I was just writing a follow-up note as your note came in. While the
> code I posted previously works fine, using which() is unnecessary.
>
> > DF <- read.csv("~/lily.csv")
> > DF$product1_1 <- NA
> > DF$product1_1 <- DF[DF$month == 1, "product1"]*3.1
> Error in `$<-.data.frame`(`*tmp*`, "product1_1", value = c(55.8, 58.9,  :
>   replacement has 4 rows, data has 7
> > DF$product1_1 <- DF[which(DF$month == 1), "product1"]*3.1
> Error in `$<-.data.frame`(`*tmp*`, "product1_1", value = c(55.8, 58.9,  :
>   replacement has 4 rows, data has 7
> > DF[DF$month == 1, "product1_1"] <- DF[DF$month == 1, "product1"]*3.1
> > DF
>   year month day product1 product2 product3 product1_1
> 1 1981 1   1   18   56   20   55.8
> 2 1981 1   2   19   45   22   58.9
> 3 1981 1   3   16   48   28   49.6
> 4 1981 1   4   19   50   21   58.9
> 5 1981 2   1   17   49   25 NA
> 6 1981 2   2   20   47   23 NA
> 7 1981 2   3   21   52   27 NA
> >
>
> The two errors above were caused because I failed to specify rows on
> the left hand side of the assignment operator, not because I failed to
> use which(). Once rows and columns are specified on both sides, the
> assignment works fine.
>
> (I do however, prefer to create an "NA" column first. Personal preference
> ;-).
>
> Best Regards,
>
> Bill.
>
>
>
> On Mon, May 22, 2017 at 11:57 PM, Ivan Calandra  wrote:
> > Hi,
> >
> > Actually, you don't need to create the column first, nor to use which:
> > DF[DF$month==1, "product1_1"] = DF[DF$month==1, "product1"] * 3.1
> >
> > The "[" is a great tool that you need to learn. In this case, you don't
> need
> > to combine "[" and $: within the square brackets, the vector before the
> > comma indexes the rows and the one after the comma indexes the columns.
> >
> > The other thing you were missing correctly referencing the rows. You
> have to
> > specify the data.frame you want to look into.
> >
> > And last, learn to use dput() to provide a nice reproducible example.
> >
> > HTH,
> > Ivan
> >
> >
> > --
> > Dr. Ivan Calandra
> > TraCEr, Laboratory for Traceology and Controlled Experiments
> > MONREPOS Archaeological Research Centre and
> > Museum for Human Behavioural Evolution
> > Schloss Monrepos
> > 56567 Neuwied, Germany
> > +49 (0) 2631 9772-243
> > https://www.researchgate.net/profile/Ivan_Calandra
> >
> > On 23/05/2017 08:45, William Michels via R-help wrote:
> >>
> >> Hi Lily,
> >>
> >> You're on the right track, but you should define a new column first
> >> (filled with NA values), then specify the precise rows and columns on
> >> both the left and right hand sides of the assignment operator that
> >> will be altered. Luckily, this is pretty easy...just remember to use
> >> which() on the right hand side of the assignment operator to get the
> >> index of the rows you want. Example below for "product1":
> >>
> >>> DF$product1_1 <- NA
> >>> DF[DF$month == 1, "product1_1"] <- DF[which(DF$month == 1),
> >>> "product1"]*3.1
> >>>
> >>
> >> HTH,
> >>
> >> Bill.
> >>
> >> William Michels, Ph.D.
> >>
> >>
> >>
> >>
> >> On Mon, May 22, 2017 at 9:56 PM, lily li  wrote:
> >>>
> >>> Hi R users,
> >>>
> >>> I have a question about manipulating the dataframe. I want to create a
> >>> new
> >>> dataframe, and to multiply rows with different seasons for different
> >>> constants.
> >>>
> >>> DF
> >>> year   month   day   product1   product2   product3
> >>> 1981 1  1 18  5620
> >>> 1981 1  2 19  4522
> >>> 1981 1  3 16  4828
> >>> 1981 1  4 19  5021
> >>> 1981 2  1 17  4925
> >>> 1981 2  2   

[R] About change columns and specific rows in R

2017-05-22 Thread lily li
Hi R users,

I have a question about manipulating the dataframe. I want to create a new
dataframe, and to multiply rows with different seasons for different
constants.

DF
year   month   day   product1   product2   product3
1981 1  1 18  5620
1981 1  2 19  4522
1981 1  3 16  4828
1981 1  4 19  5021
1981 2  1 17  4925
1981 2  2 20  4723
1981 2  3 21  5227

For example, how to multiply product1 in month1 by 3.1, and to multiply
product3 in month2 by 2.0? I wrote the code like this but does not work.
Thanks for your help.

DF['month'==1, ]$product1_1 = DF['month'==1, ]$product1 * 3.1;
DF['month'==2, ]$product3_1 = DF['month'==1, ]$product3 * 2.0;

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About calculating average values from several matrices

2017-05-09 Thread lily li
yes, I just tried for the dataframe and it works, so there is no problem on
this side.

On Tue, May 9, 2017 at 9:14 AM, Doran, Harold  wrote:

> Im not sure if you’re asking a question or confirming that it works for
> you. But, obviously, the code below behaves as expected
>
>
>
> *From:* lily li [mailto:chocol...@gmail.com]
> *Sent:* Tuesday, May 09, 2017 11:13 AM
> *To:* Doran, Harold 
> *Cc:* Charles Determan ; R mailing list <
> r-help@r-project.org>
>
> *Subject:* Re: [R] About calculating average values from several matrices
>
>
>
> Yes, that means to control decimal numbers. For example, use round(2.3122,
> digits=1), it gets 2.3
>
>
>
> On Tue, May 9, 2017 at 9:11 AM, Doran, Harold  wrote:
>
> ?round
>
>
>
>
>
> *From:* lily li [mailto:chocol...@gmail.com]
> *Sent:* Tuesday, May 09, 2017 11:10 AM
> *To:* Charles Determan 
> *Cc:* Doran, Harold ; R mailing list  >
> *Subject:* Re: [R] About calculating average values from several matrices
>
>
>
> Thanks very much, it works. But how to round the values to have only 1
> decimal digit or 2 decimal digits? I think by dividing, the values are
> double type now. Thanks again.
>
>
>
>
>
> On Tue, May 9, 2017 at 9:04 AM, Charles Determan 
> wrote:
>
> If you want the mean of each element across you list of matrices the
> following should provide what you are looking for where Reduce sums all
> your matrix elements across matrices and the simply divided my the number
> of matrices for the element-wise mean.
>
> Reduce(`+`, mylist)/length(mylist)
>
> Regards,
>
> Charles
>
>
>
> On Tue, May 9, 2017 at 9:52 AM, lily li  wrote:
>
> I meant for each cell, it takes the average from other dataframes at the
> same cell. I don't know how to deal with row names and col names though, so
> it has the error message.
>
> On Tue, May 9, 2017 at 8:50 AM, Doran, Harold  wrote:
>
> > It’s not clear to me what your actual structure is. Can you provide
> > str(object)? Assuming it is a list, and you want the mean over all cells
> or
> > columns, you might want like this:
> >
> >
> >
> > myData <- vector("list", 3)
> >
> >
> >
> > for(i in 1:3){
> >
> >         myData[[i]] <- matrix(rnorm(100), 10, 10)
> >
> > }
> >
> >
> >
> > ### mean over all cells
> >
> > sapply(myData, function(x) mean(x))
> >
> >
> >
> > ### mean over all columns
> >
> > sapply(myData, function(x) colMeans(x))
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > *From:* lily li [mailto:chocol...@gmail.com]
> > *Sent:* Tuesday, May 09, 2017 10:44 AM
> > *To:* Doran, Harold 
> > *Cc:* R mailing list 
> > *Subject:* Re: [R] About calculating average values from several matrices
>
>
> >
> >
> >
> > I'm trying to get a new dataframe or whatever to call, which has the same
> > structure with each file as listed above. For each cell in the new
> > dataframe or the new file, it is the average value from former dataframes
> > at the same location. Thanks.
> >
> >
> >
> > On Tue, May 9, 2017 at 8:41 AM, Doran, Harold  wrote:
> >
> > Are you trying to take the mean over all cells, or over rows/columns
> > within each dataframe. Also, are these different dataframes stored
> within a
> > list or are they standalone?
> >
> >
> >
> >
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
> > Sent: Tuesday, May 09, 2017 10:39 AM
> > To: R mailing list 
>
> > Subject: [R] About calculating average values from several matrices
> >
> > Hi R users,
> >
> > I have a question about manipulating the data.
> > For example, there are several such data frames or matrices, and I want
> to
> > calculate the average value from all the data frames or matrices. How to
> do
> > it? Also, should I convert them to data frame or matrix first? Right now,
> > when I use typeof() function, each one is a list.
> >
> > file1
> > jan   feb   mar   apr   may   jun   jul   aug   sep   oct
>  nov
> >
> > app1   1.1   1.20.80.9   1.31.5   2.2   3.2   3.01.2
>  1.1
> > app2   3.1   3.22.82.5   2.32.5   3.2   3.0   2.91.8
>  1.8
> > app3   5.1   5.23.84.9   5.35.5   5.2   4.2   5.04.2
>  4.1
> >
> > file2
> > jan   feb   mar   apr   ma

Re: [R] About calculating average values from several matrices

2017-05-09 Thread lily li
Yes, that means to control decimal numbers. For example, use round(2.3122,
digits=1), it gets 2.3

On Tue, May 9, 2017 at 9:11 AM, Doran, Harold  wrote:

> ?round
>
>
>
>
>
> *From:* lily li [mailto:chocol...@gmail.com]
> *Sent:* Tuesday, May 09, 2017 11:10 AM
> *To:* Charles Determan 
> *Cc:* Doran, Harold ; R mailing list  >
> *Subject:* Re: [R] About calculating average values from several matrices
>
>
>
> Thanks very much, it works. But how to round the values to have only 1
> decimal digit or 2 decimal digits? I think by dividing, the values are
> double type now. Thanks again.
>
>
>
>
>
> On Tue, May 9, 2017 at 9:04 AM, Charles Determan 
> wrote:
>
> If you want the mean of each element across you list of matrices the
> following should provide what you are looking for where Reduce sums all
> your matrix elements across matrices and the simply divided my the number
> of matrices for the element-wise mean.
>
> Reduce(`+`, mylist)/length(mylist)
>
> Regards,
>
> Charles
>
>
>
> On Tue, May 9, 2017 at 9:52 AM, lily li  wrote:
>
> I meant for each cell, it takes the average from other dataframes at the
> same cell. I don't know how to deal with row names and col names though, so
> it has the error message.
>
> On Tue, May 9, 2017 at 8:50 AM, Doran, Harold  wrote:
>
> > It’s not clear to me what your actual structure is. Can you provide
> > str(object)? Assuming it is a list, and you want the mean over all cells
> or
> > columns, you might want like this:
> >
> >
> >
> > myData <- vector("list", 3)
> >
> >
> >
> > for(i in 1:3){
> >
> > myData[[i]] <- matrix(rnorm(100), 10, 10)
> >
> > }
> >
> >
> >
> > ### mean over all cells
> >
> > sapply(myData, function(x) mean(x))
> >
> >
> >
> > ### mean over all columns
> >
> > sapply(myData, function(x) colMeans(x))
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > *From:* lily li [mailto:chocol...@gmail.com]
> > *Sent:* Tuesday, May 09, 2017 10:44 AM
> > *To:* Doran, Harold 
> > *Cc:* R mailing list 
> > *Subject:* Re: [R] About calculating average values from several matrices
>
>
> >
> >
> >
> > I'm trying to get a new dataframe or whatever to call, which has the same
> > structure with each file as listed above. For each cell in the new
> > dataframe or the new file, it is the average value from former dataframes
> > at the same location. Thanks.
> >
> >
> >
> > On Tue, May 9, 2017 at 8:41 AM, Doran, Harold  wrote:
> >
> > Are you trying to take the mean over all cells, or over rows/columns
> > within each dataframe. Also, are these different dataframes stored
> within a
> > list or are they standalone?
> >
> >
> >
> >
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
> > Sent: Tuesday, May 09, 2017 10:39 AM
> > To: R mailing list 
>
> > Subject: [R] About calculating average values from several matrices
> >
> > Hi R users,
> >
> > I have a question about manipulating the data.
> > For example, there are several such data frames or matrices, and I want
> to
> > calculate the average value from all the data frames or matrices. How to
> do
> > it? Also, should I convert them to data frame or matrix first? Right now,
> > when I use typeof() function, each one is a list.
> >
> > file1
> > jan   feb   mar   apr   may   jun   jul   aug   sep   oct
>  nov
> >
> > app1   1.1   1.20.80.9   1.31.5   2.2   3.2   3.01.2
>  1.1
> > app2   3.1   3.22.82.5   2.32.5   3.2   3.0   2.91.8
>  1.8
> > app3   5.1   5.23.84.9   5.35.5   5.2   4.2   5.04.2
>  4.1
> >
> > file2
> > jan   feb   mar   apr   may   jun   jul   aug   sep   oct
>  nov
> >
> > app1   1.9   1.50.50.9   1.21.8   2.5   3.7   3.21.5
>  1.6
> > app2   3.5   3.72.32.2   2.52.0   3.6   3.2   2.81.2
>  1.4
> > app3   5.5   5.03.54.4   5.45.6   5.3   4.4   5.24.3
>  4.2
> >
> > file3 has the similar structure and values...
> >
> > There are eight such files, and when I use the function mean(file1,
> file2,
> > file3, ..., file8), it returns the error below. Thanks for your help.
> >
> > Warning message:
> > In mean.default(file1,

Re: [R] About calculating average values from several matrices

2017-05-09 Thread lily li
Thanks very much, it works. But how to round the values to have only 1
decimal digit or 2 decimal digits? I think by dividing, the values are
double type now. Thanks again.


On Tue, May 9, 2017 at 9:04 AM, Charles Determan 
wrote:

> If you want the mean of each element across you list of matrices the
> following should provide what you are looking for where Reduce sums all
> your matrix elements across matrices and the simply divided my the number
> of matrices for the element-wise mean.
>
> Reduce(`+`, mylist)/length(mylist)
>
> Regards,
> Charles
>
> On Tue, May 9, 2017 at 9:52 AM, lily li  wrote:
>
>> I meant for each cell, it takes the average from other dataframes at the
>> same cell. I don't know how to deal with row names and col names though,
>> so
>> it has the error message.
>>
>> On Tue, May 9, 2017 at 8:50 AM, Doran, Harold  wrote:
>>
>> > It’s not clear to me what your actual structure is. Can you provide
>> > str(object)? Assuming it is a list, and you want the mean over all
>> cells or
>> > columns, you might want like this:
>> >
>> >
>> >
>> > myData <- vector("list", 3)
>> >
>> >
>> >
>> > for(i in 1:3){
>> >
>> > myData[[i]] <- matrix(rnorm(100), 10, 10)
>> >
>> > }
>> >
>> >
>> >
>> > ### mean over all cells
>> >
>> > sapply(myData, function(x) mean(x))
>> >
>> >
>> >
>> > ### mean over all columns
>> >
>> > sapply(myData, function(x) colMeans(x))
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > *From:* lily li [mailto:chocol...@gmail.com]
>> > *Sent:* Tuesday, May 09, 2017 10:44 AM
>> > *To:* Doran, Harold 
>> > *Cc:* R mailing list 
>> > *Subject:* Re: [R] About calculating average values from several
>> matrices
>>
>> >
>> >
>> >
>> > I'm trying to get a new dataframe or whatever to call, which has the
>> same
>> > structure with each file as listed above. For each cell in the new
>> > dataframe or the new file, it is the average value from former
>> dataframes
>> > at the same location. Thanks.
>> >
>> >
>> >
>> > On Tue, May 9, 2017 at 8:41 AM, Doran, Harold  wrote:
>> >
>> > Are you trying to take the mean over all cells, or over rows/columns
>> > within each dataframe. Also, are these different dataframes stored
>> within a
>> > list or are they standalone?
>> >
>> >
>> >
>> >
>> > -Original Message-
>> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
>> > Sent: Tuesday, May 09, 2017 10:39 AM
>> > To: R mailing list 
>> > Subject: [R] About calculating average values from several matrices
>> >
>> > Hi R users,
>> >
>> > I have a question about manipulating the data.
>> > For example, there are several such data frames or matrices, and I want
>> to
>> > calculate the average value from all the data frames or matrices. How
>> to do
>> > it? Also, should I convert them to data frame or matrix first? Right
>> now,
>> > when I use typeof() function, each one is a list.
>> >
>> > file1
>> > jan   feb   mar   apr   may   jun   jul   aug   sep   oct
>>  nov
>> >
>> > app1   1.1   1.20.80.9   1.31.5   2.2   3.2   3.01.2
>>  1.1
>> > app2   3.1   3.22.82.5   2.32.5   3.2   3.0   2.91.8
>>  1.8
>> > app3   5.1   5.23.84.9   5.35.5   5.2   4.2   5.04.2
>>  4.1
>> >
>> > file2
>> > jan   feb   mar   apr   may   jun   jul   aug   sep   oct
>>  nov
>> >
>> > app1   1.9   1.50.50.9   1.21.8   2.5   3.7   3.21.5
>>  1.6
>> > app2   3.5   3.72.32.2   2.52.0   3.6   3.2   2.81.2
>>  1.4
>> > app3   5.5   5.03.54.4   5.45.6   5.3   4.4   5.24.3
>>  4.2
>> >
>> > file3 has the similar structure and values...
>> >
>> > There are eight such files, and when I use the function mean(file1,
>> file2,
>> > file3, ..., file8), it returns the error below. Thanks for your help.
>> >
>> > Warning message:
>> > In mean.default(file1, file2, file3, file4,

Re: [R] About calculating average values from several matrices

2017-05-09 Thread lily li
I meant for each cell, it takes the average from other dataframes at the
same cell. I don't know how to deal with row names and col names though, so
it has the error message.

On Tue, May 9, 2017 at 8:50 AM, Doran, Harold  wrote:

> It’s not clear to me what your actual structure is. Can you provide
> str(object)? Assuming it is a list, and you want the mean over all cells or
> columns, you might want like this:
>
>
>
> myData <- vector("list", 3)
>
>
>
> for(i in 1:3){
>
> myData[[i]] <- matrix(rnorm(100), 10, 10)
>
> }
>
>
>
> ### mean over all cells
>
> sapply(myData, function(x) mean(x))
>
>
>
> ### mean over all columns
>
> sapply(myData, function(x) colMeans(x))
>
>
>
>
>
>
>
>
>
>
>
> *From:* lily li [mailto:chocol...@gmail.com]
> *Sent:* Tuesday, May 09, 2017 10:44 AM
> *To:* Doran, Harold 
> *Cc:* R mailing list 
> *Subject:* Re: [R] About calculating average values from several matrices
>
>
>
> I'm trying to get a new dataframe or whatever to call, which has the same
> structure with each file as listed above. For each cell in the new
> dataframe or the new file, it is the average value from former dataframes
> at the same location. Thanks.
>
>
>
> On Tue, May 9, 2017 at 8:41 AM, Doran, Harold  wrote:
>
> Are you trying to take the mean over all cells, or over rows/columns
> within each dataframe. Also, are these different dataframes stored within a
> list or are they standalone?
>
>
>
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
> Sent: Tuesday, May 09, 2017 10:39 AM
> To: R mailing list 
> Subject: [R] About calculating average values from several matrices
>
> Hi R users,
>
> I have a question about manipulating the data.
> For example, there are several such data frames or matrices, and I want to
> calculate the average value from all the data frames or matrices. How to do
> it? Also, should I convert them to data frame or matrix first? Right now,
> when I use typeof() function, each one is a list.
>
> file1
> jan   feb   mar   apr   may   jun   jul   aug   sep   oct   nov
>
> app1   1.1   1.20.80.9   1.31.5   2.2   3.2   3.01.2   1.1
> app2   3.1   3.22.82.5   2.32.5   3.2   3.0   2.91.8   1.8
> app3   5.1   5.23.84.9   5.35.5   5.2   4.2   5.04.2   4.1
>
> file2
> jan   feb   mar   apr   may   jun   jul   aug   sep   oct   nov
>
> app1   1.9   1.50.50.9   1.21.8   2.5   3.7   3.21.5   1.6
> app2   3.5   3.72.32.2   2.52.0   3.6   3.2   2.81.2   1.4
> app3   5.5   5.03.54.4   5.45.6   5.3   4.4   5.24.3   4.2
>
> file3 has the similar structure and values...
>
> There are eight such files, and when I use the function mean(file1, file2,
> file3, ..., file8), it returns the error below. Thanks for your help.
>
> Warning message:
> In mean.default(file1, file2, file3, file4, file5, file6, file7,  :
>   argument is not numeric or logical: returning NA
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] About calculating average values from several matrices

2017-05-09 Thread lily li
I'm trying to get a new dataframe or whatever to call, which has the same
structure with each file as listed above. For each cell in the new
dataframe or the new file, it is the average value from former dataframes
at the same location. Thanks.

On Tue, May 9, 2017 at 8:41 AM, Doran, Harold  wrote:

> Are you trying to take the mean over all cells, or over rows/columns
> within each dataframe. Also, are these different dataframes stored within a
> list or are they standalone?
>
>
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
> Sent: Tuesday, May 09, 2017 10:39 AM
> To: R mailing list 
> Subject: [R] About calculating average values from several matrices
>
> Hi R users,
>
> I have a question about manipulating the data.
> For example, there are several such data frames or matrices, and I want to
> calculate the average value from all the data frames or matrices. How to do
> it? Also, should I convert them to data frame or matrix first? Right now,
> when I use typeof() function, each one is a list.
>
> file1
> jan   feb   mar   apr   may   jun   jul   aug   sep   oct   nov
>
> app1   1.1   1.20.80.9   1.31.5   2.2   3.2   3.01.2   1.1
> app2   3.1   3.22.82.5   2.32.5   3.2   3.0   2.91.8   1.8
> app3   5.1   5.23.84.9   5.35.5   5.2   4.2   5.04.2   4.1
>
> file2
> jan   feb   mar   apr   may   jun   jul   aug   sep   oct   nov
>
> app1   1.9   1.50.50.9   1.21.8   2.5   3.7   3.21.5   1.6
> app2   3.5   3.72.32.2   2.52.0   3.6   3.2   2.81.2   1.4
> app3   5.5   5.03.54.4   5.45.6   5.3   4.4   5.24.3   4.2
>
> file3 has the similar structure and values...
>
> There are eight such files, and when I use the function mean(file1, file2,
> file3, ..., file8), it returns the error below. Thanks for your help.
>
> Warning message:
> In mean.default(file1, file2, file3, file4, file5, file6, file7,  :
>   argument is not numeric or logical: returning NA
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] About calculating average values from several matrices

2017-05-09 Thread lily li
Hi R users,

I have a question about manipulating the data.
For example, there are several such data frames or matrices, and I want to
calculate the average value from all the data frames or matrices. How to do
it? Also, should I convert them to data frame or matrix first? Right now,
when I use typeof() function, each one is a list.

file1
jan   feb   mar   apr   may   jun   jul   aug   sep   oct   nov

app1   1.1   1.20.80.9   1.31.5   2.2   3.2   3.01.2   1.1
app2   3.1   3.22.82.5   2.32.5   3.2   3.0   2.91.8   1.8
app3   5.1   5.23.84.9   5.35.5   5.2   4.2   5.04.2   4.1

file2
jan   feb   mar   apr   may   jun   jul   aug   sep   oct   nov

app1   1.9   1.50.50.9   1.21.8   2.5   3.7   3.21.5   1.6
app2   3.5   3.72.32.2   2.52.0   3.6   3.2   2.81.2   1.4
app3   5.5   5.03.54.4   5.45.6   5.3   4.4   5.24.3   4.2

file3 has the similar structure and values...

There are eight such files, and when I use the function mean(file1, file2,
file3, ..., file8), it returns the error below. Thanks for your help.

Warning message:
In mean.default(file1, file2, file3, file4, file5, file6, file7,  :
  argument is not numeric or logical: returning NA

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About error in the panel

2017-03-11 Thread lily li
I think this is the problem. How to solve then?

On Sat, Mar 11, 2017 at 12:18 PM, Bert Gunter 
wrote:

> Typo, should be:
>
> 3. A guess: You are sourcing the entire script in the editor panel
> into R, and there is something screwed up there.
>
> -- Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sat, Mar 11, 2017 at 11:14 AM, lily li  wrote:
> > Thanks for your reply. I thought anything about R questions can be posted
> > here.
> >
> > About your third point, what does it mean? I did the same thing before
> for
> > other scripts, but this one does not work. Thanks again.
> >
> > On Sat, Mar 11, 2017 at 12:12 PM, Bert Gunter 
> > wrote:
> >>
> >> 1. Not reproducible, hence impossible to say.
> >>
> >> 2. This is r-help. RStudio is totally separate and its own support page.
> >>
> >> 3. A guess: Use are sourcing the entire script in the editor panel
> >> into R, and there is something screwed up there.
> >>
> >> Cheers,
> >> Bert
> >>
> >>
> >> Bert Gunter
> >>
> >> "The trouble with having an open mind is that people keep coming along
> >> and sticking things into it."
> >> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
> >>
> >>
> >> On Sat, Mar 11, 2017 at 10:50 AM, lily li  wrote:
> >> > Hi R users,
> >> >
> >> > I have a problem about using R studio. For example, there is a
> dataframe
> >> > that has many columns. I want to aggregated column X and column Y into
> >> > column Z. Column Z does not exist before the aggregation. I use the
> code
> >> > below:
> >> > df$Z = df$X + df$Y
> >> >
> >> > However, it does not work in the top left panel in Rstudio, and has
> the
> >> > following warning message:
> >> > Error in `$<-.data.frame`(`*tmp*`, "Z", value = numeric(0)) :
> >> >   replacement has 0 rows, data has 34333
> >> >
> >> > If I type the same code in the Console panel (bottom left panel), it
> >> > works.
> >> > How to deal with this problem? Thanks.
> >> >
> >> > [[alternative HTML version deleted]]
> >> >
> >> > __
> >> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> > https://stat.ethz.ch/mailman/listinfo/r-help
> >> > PLEASE do read the posting guide
> >> > http://www.R-project.org/posting-guide.html
> >> > and provide commented, minimal, self-contained, reproducible code.
> >
> >
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About error in the panel

2017-03-11 Thread lily li
Thanks for your reply. I thought anything about R questions can be posted
here.

About your third point, what does it mean? I did the same thing before for
other scripts, but this one does not work. Thanks again.

On Sat, Mar 11, 2017 at 12:12 PM, Bert Gunter 
wrote:

> 1. Not reproducible, hence impossible to say.
>
> 2. This is r-help. RStudio is totally separate and its own support page.
>
> 3. A guess: Use are sourcing the entire script in the editor panel
> into R, and there is something screwed up there.
>
> Cheers,
> Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sat, Mar 11, 2017 at 10:50 AM, lily li  wrote:
> > Hi R users,
> >
> > I have a problem about using R studio. For example, there is a dataframe
> > that has many columns. I want to aggregated column X and column Y into
> > column Z. Column Z does not exist before the aggregation. I use the code
> > below:
> > df$Z = df$X + df$Y
> >
> > However, it does not work in the top left panel in Rstudio, and has the
> > following warning message:
> > Error in `$<-.data.frame`(`*tmp*`, "Z", value = numeric(0)) :
> >   replacement has 0 rows, data has 34333
> >
> > If I type the same code in the Console panel (bottom left panel), it
> works.
> > How to deal with this problem? Thanks.
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About error in the panel

2017-03-11 Thread lily li
More specifically,  it shows the following when I typed traceback():

3: stop(sprintf(ngettext(N, "replacement has %d row, data has %d",
   "replacement has %d rows, data has %d"), N, nrows), domain = NA)
2: `$<-.data.frame`(`*tmp*`, "Z", value = numeric(0))
1: `$<-`(`*tmp*`, "Z", value = numeric(0))

I don't know what is the problem, as it works in the Console panel but not
in the top left panel. Thanks for your help.

On Sat, Mar 11, 2017 at 11:50 AM, lily li  wrote:

> Hi R users,
>
> I have a problem about using R studio. For example, there is a dataframe
> that has many columns. I want to aggregated column X and column Y into
> column Z. Column Z does not exist before the aggregation. I use the code
> below:
> df$Z = df$X + df$Y
>
> However, it does not work in the top left panel in Rstudio, and has the
> following warning message:
> Error in `$<-.data.frame`(`*tmp*`, "Z", value = numeric(0)) :
>   replacement has 0 rows, data has 34333
>
> If I type the same code in the Console panel (bottom left panel), it
> works. How to deal with this problem? Thanks.
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] About error in the panel

2017-03-11 Thread lily li
Hi R users,

I have a problem about using R studio. For example, there is a dataframe
that has many columns. I want to aggregated column X and column Y into
column Z. Column Z does not exist before the aggregation. I use the code
below:
df$Z = df$X + df$Y

However, it does not work in the top left panel in Rstudio, and has the
following warning message:
Error in `$<-.data.frame`(`*tmp*`, "Z", value = numeric(0)) :
  replacement has 0 rows, data has 34333

If I type the same code in the Console panel (bottom left panel), it works.
How to deal with this problem? Thanks.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About installing the lubridate package

2017-03-07 Thread lily li
Thanks, Bert. This website is comprehensive. So for any kind of packages in
the future, can I just download from this website? I did a search from
google before.

On Tue, Mar 7, 2017 at 12:14 PM, Bert Gunter  wrote:

> Huh?
>
> I just installed the Mavericks binary on my OSX Sierra without problems:
>
> install.packages("lubridate", repos='https://cran.revolutionanalytics.com
> ')
>
> A google search would have found this essentially instantly!
>
> As for native R functions for parsing dates: of course!
>
> ?strptime
>
> Again, a google search would have found this (e.g. on "parse dates in
> R"). Please make a minimal effort to search before posting such "where
> do I find" queries here.
>
> Cheers,
> Bert
>
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Tue, Mar 7, 2017 at 10:45 AM, lily li  wrote:
> > Hi R users,
> >
> > I'd like to ask that where to find the 'lubridate' package for Mac
> Sierra?
> > I downloaded one version for OS X Mavericks binaries, but it does not
> work.
> >
> > The error message is as below:
> >> install.packages("~/Downloads/lubridate_1.6.0.tar.gz", repos = NULL,
> type
> > = "source")
> > ERROR: dependency ‘stringr’ is not available for package ‘lubridate’
> > * removing
> > ‘/Library/Frameworks/R.framework/Versions/3.3/
> Resources/library/lubridate’
> > Warning in install.packages :
> >   installation of package
> > ‘/Users/qinghuan/Downloads/lubridate_1.6.0.tar.gz’ had non-zero exit
> status
> >
> > How to install the proper package? Thanks for your help.
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] About installing the lubridate package

2017-03-07 Thread lily li
Or if there is another way to get '', 'mm', and 'dd' from time variable
'dd-mm-'? Thanks very much.


On Tue, Mar 7, 2017 at 11:45 AM, lily li  wrote:

> Hi R users,
>
> I'd like to ask that where to find the 'lubridate' package for Mac Sierra?
> I downloaded one version for OS X Mavericks binaries, but it does not
> work.
>
> The error message is as below:
> > install.packages("~/Downloads/lubridate_1.6.0.tar.gz", repos = NULL,
> type = "source")
> ERROR: dependency ‘stringr’ is not available for package ‘lubridate’
> * removing ‘/Library/Frameworks/R.framework/Versions/3.3/
> Resources/library/lubridate’
> Warning in install.packages :
>   installation of package ‘/Users/qinghuan/Downloads/lubridate_1.6.0.tar.gz’
> had non-zero exit status
>
> How to install the proper package? Thanks for your help.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] About installing the lubridate package

2017-03-07 Thread lily li
Hi R users,

I'd like to ask that where to find the 'lubridate' package for Mac Sierra?
I downloaded one version for OS X Mavericks binaries, but it does not work.

The error message is as below:
> install.packages("~/Downloads/lubridate_1.6.0.tar.gz", repos = NULL, type
= "source")
ERROR: dependency ‘stringr’ is not available for package ‘lubridate’
* removing
‘/Library/Frameworks/R.framework/Versions/3.3/Resources/library/lubridate’
Warning in install.packages :
  installation of package
‘/Users/qinghuan/Downloads/lubridate_1.6.0.tar.gz’ had non-zero exit status

How to install the proper package? Thanks for your help.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Re: [R] converting time format

2017-02-22 Thread lily li
Yes, it is a little different. Is there a way to get '-mm' format?
Thanks.

On Wed, Feb 22, 2017 at 2:10 PM, Jim Lemon  wrote:

> Hi Lily.
> Two problems. You have named the month field "mon" and then refer to
> it as "month". Second, as the resolution of as.Date is days, it can't
> produce a valid date without specifying the day. Thus:
>
> df.count.mon<-data.frame(count=sample(1:24,24),
>  year=rep(2014:2015,each=2),mon=rep(1:12,2))
> # make each day the first day of the month
> df.count.mon$time<-
>  as.Date(paste(df.count.mon$year, df.count.mon$mon,1),
>  '%Y %m %d')
> df.count.mon
>count year mon   time
> 1 22 2014   1 2014-01-01
> 2 12 2014   2 2014-02-01
> ...
> You will get values, but I don't think they are the ones you want.
>
> Jim
>
> On Thu, Feb 23, 2017 at 6:33 AM, lily li  wrote:
> > Hi R users,
> >
> > I have a dataframe, with year, month, day, and other variables. I wanted
> to
> > calculated monthly values of the variables. For example, there is one
> > variable called 'count'. I use the code below to convert daily data to
> > monthly data.
> >
> > df.count.mon = aggregate(count ~ year+month, data= df, sum)
> >
> > The new dataframe has three columns: year, month, and count. Now I want
> to
> > add one more column as 'time', which has the format '-mm'. I use the
> > code below but the new column has all NA values. What is the problem and
> > how to solve it?
> >
> > df.count.mon$time = as.Date(paste(df.count.mon$year,
> df.count.mon$month),
> > '%Y %m')
> >
> > I had experience to add one more column with the format '-mm-dd',
> which
> > works, but not with monthly format. Thanks for your help.
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] converting time format

2017-02-22 Thread lily li
Hi R users,

I have a dataframe, with year, month, day, and other variables. I wanted to
calculated monthly values of the variables. For example, there is one
variable called 'count'. I use the code below to convert daily data to
monthly data.

df.count.mon = aggregate(count ~ year+month, data= df, sum)

The new dataframe has three columns: year, month, and count. Now I want to
add one more column as 'time', which has the format '-mm'. I use the
code below but the new column has all NA values. What is the problem and
how to solve it?

df.count.mon$time = as.Date(paste(df.count.mon$year, df.count.mon$month),
'%Y %m')

I had experience to add one more column with the format '-mm-dd', which
works, but not with monthly format. Thanks for your help.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] reading data

2017-01-19 Thread lily li
Hi R users,

I'm trying to open netcdf files in R. Each nc file has daily climate
measurements for a whole year, covering the whole US. How to limit the file
to a specific rectangle? Thanks.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About populating a dataframe in a loop

2017-01-06 Thread lily li
Thanks, Richard. But if the data cannot fill the constructed data frame,
will there be NA values?


On Fri, Jan 6, 2017 at 10:07 PM, Richard M. Heiberger 
wrote:

> Incrementally increasing the size of an array is not efficient in R.
> The recommended technique is to allocate as much space as you will
> need, and then fill it.
>
> > system.time({tmp <- 1:5 ; for (i in 1:1000) tmp <- rbind(tmp, 1:5)})
>user  system elapsed
>   0.011   0.000   0.011
> > dim(tmp)
> [1] 10015
> > system.time({tmp <- matrix(NA, 1001, 5); for (i in 1:1001) tmp[i,] <-
> 1:5})
>user  system elapsed
>   0.001   0.000   0.001
> > dim(tmp)
> [1] 10015
>
> On Fri, Jan 6, 2017 at 11:46 PM, lily li  wrote:
> > Hi Rui,
> >
> > Thanks for your reply. Yes, when I tried to rbind two dataframes, it
> works.
> > However, if there are more than 50, it got stuck for hours. When I tried
> to
> > terminate the process and open the csv file separately, it has only one
> > data frame. What is the problem? Thanks.
> >
> >
> > On Fri, Jan 6, 2017 at 11:12 AM, Rui Barradas 
> wrote:
> >
> >> Hello,
> >>
> >> Works with me:
> >>
> >> set.seed(6574)
> >>
> >> pre.mat = data.frame()
> >> for(i in 1:10){
> >> mat.temp = data.frame(x = rnorm(5), A = sample(LETTERS, 5, TRUE))
> >> pre.mat = rbind(pre.mat, mat.temp)
> >> }
> >>
> >> nrow(pre.mat)  # should be 50
> >>
> >>
> >> Can you give us an example that doesn't work?
> >>
> >> Rui Barradas
> >>
> >>
> >> Em 06-01-2017 18:00, lily li escreveu:
> >>
> >>> Hi R users,
> >>>
> >>> I have a question about filling a dataframe in R using a for loop.
> >>>
> >>> I created an empty dataframe first and then filled it, using the code:
> >>> pre.mat = data.frame()
> >>> for(i in 1:10){
> >>>  mat.temp = data.frame(some values filled in)
> >>>  pre.mat = rbind(pre.mat, mat.temp)
> >>> }
> >>> However, the resulted dataframe has not all the rows that I desired
> for.
> >>> What is the problem and how to solve it? Thanks.
> >>>
> >>> [[alternative HTML version deleted]]
> >>>
> >>> __
> >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>> https://stat.ethz.ch/mailman/listinfo/r-help
> >>> PLEASE do read the posting guide http://www.R-project.org/posti
> >>> ng-guide.html
> >>> and provide commented, minimal, self-contained, reproducible code.
> >>>
> >>>
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About populating a dataframe in a loop

2017-01-06 Thread lily li
Hi Rui,

Thanks for your reply. Yes, when I tried to rbind two dataframes, it works.
However, if there are more than 50, it got stuck for hours. When I tried to
terminate the process and open the csv file separately, it has only one
data frame. What is the problem? Thanks.


On Fri, Jan 6, 2017 at 11:12 AM, Rui Barradas  wrote:

> Hello,
>
> Works with me:
>
> set.seed(6574)
>
> pre.mat = data.frame()
> for(i in 1:10){
> mat.temp = data.frame(x = rnorm(5), A = sample(LETTERS, 5, TRUE))
> pre.mat = rbind(pre.mat, mat.temp)
> }
>
> nrow(pre.mat)  # should be 50
>
>
> Can you give us an example that doesn't work?
>
> Rui Barradas
>
>
> Em 06-01-2017 18:00, lily li escreveu:
>
>> Hi R users,
>>
>> I have a question about filling a dataframe in R using a for loop.
>>
>> I created an empty dataframe first and then filled it, using the code:
>> pre.mat = data.frame()
>> for(i in 1:10){
>>  mat.temp = data.frame(some values filled in)
>>  pre.mat = rbind(pre.mat, mat.temp)
>> }
>> However, the resulted dataframe has not all the rows that I desired for.
>> What is the problem and how to solve it? Thanks.
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] About populating a dataframe in a loop

2017-01-06 Thread lily li
Hi R users,

I have a question about filling a dataframe in R using a for loop.

I created an empty dataframe first and then filled it, using the code:
pre.mat = data.frame()
for(i in 1:10){
mat.temp = data.frame(some values filled in)
pre.mat = rbind(pre.mat, mat.temp)
}
However, the resulted dataframe has not all the rows that I desired for.
What is the problem and how to solve it? Thanks.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About concatenating strings

2017-01-05 Thread lily li
Sorry for the emails. I just checked and the problem is still there. Is
there a proper way to reformat the decimal places, such as three or four
decimal places? Thanks.

If maintain four decimal places, the numbers are: 1.2000, 1.3100, 1.4000,
etc.

On Thu, Jan 5, 2017 at 10:46 PM, lily li  wrote:

> I found that the last column is the digits 2.00, so the problem is solved.
>
> On Thu, Jan 5, 2017 at 10:42 PM, lily li  wrote:
>
>> Hi R users,
>>
>> I'm trying to concatenate two strings, while each string has numbers.
>> For example, strings1 = c(1.2, 1.31, 1.4, 1.51, etc), strings2= c(2.1,
>> 2.22, 2.3, 2.44, etc). I want to have all decimals for the two strings,
>> such as: strings1= c(1.20, 1.31, 1.40, 1.51, etc), string2 = c(2.10, 2.22,
>> 2.30, 2.44, etc).
>> After concatenating, they become c(1.20--2.10, 1.31--2.22, 1.40--2.30,
>> 1.51--2.44, etc)
>> I use the code below, but after digits=2 in the parentheses, the length
>> of each string has one more. What is the problem and how to do it another
>> way? Thanks.
>>
>> cons  = paste(c(strings1, digits=2), c(strings2, digits=2), sep='-')
>>
>>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About concatenating strings

2017-01-05 Thread lily li
I found that the last column is the digits 2.00, so the problem is solved.

On Thu, Jan 5, 2017 at 10:42 PM, lily li  wrote:

> Hi R users,
>
> I'm trying to concatenate two strings, while each string has numbers.
> For example, strings1 = c(1.2, 1.31, 1.4, 1.51, etc), strings2= c(2.1,
> 2.22, 2.3, 2.44, etc). I want to have all decimals for the two strings,
> such as: strings1= c(1.20, 1.31, 1.40, 1.51, etc), string2 = c(2.10, 2.22,
> 2.30, 2.44, etc).
> After concatenating, they become c(1.20--2.10, 1.31--2.22, 1.40--2.30,
> 1.51--2.44, etc)
> I use the code below, but after digits=2 in the parentheses, the length of
> each string has one more. What is the problem and how to do it another way?
> Thanks.
>
> cons  = paste(c(strings1, digits=2), c(strings2, digits=2), sep='-')
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] About concatenating strings

2017-01-05 Thread lily li
Hi R users,

I'm trying to concatenate two strings, while each string has numbers.
For example, strings1 = c(1.2, 1.31, 1.4, 1.51, etc), strings2= c(2.1,
2.22, 2.3, 2.44, etc). I want to have all decimals for the two strings,
such as: strings1= c(1.20, 1.31, 1.40, 1.51, etc), string2 = c(2.10, 2.22,
2.30, 2.44, etc).
After concatenating, they become c(1.20--2.10, 1.31--2.22, 1.40--2.30,
1.51--2.44, etc)
I use the code below, but after digits=2 in the parentheses, the length of
each string has one more. What is the problem and how to do it another way?
Thanks.

cons  = paste(c(strings1, digits=2), c(strings2, digits=2), sep='-')

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about data format in R

2016-12-31 Thread lily li
Sorry, the problem has been solved. I found that strptime is a good
function for this.
DF$time2 = strptime(DF$time, format='%Y-%m-%d)


On Sat, Dec 31, 2016 at 11:02 AM, lily li  wrote:

> I tried it, but it doesn't work. The time column is blank then.
> DF$time = substring(DF$time, first=as.Date('1999-01-01),
> last=as.Date('2005-12-30'))
>
> On Sat, Dec 31, 2016 at 10:52 AM, David Winsemius 
> wrote:
>
>>
>> > On Dec 31, 2016, at 9:26 AM, lily li  wrote:
>> >
>> > Hi all,
>> >
>> > Thanks for your help. Now I can convert data to the format "-mm-dd
>> > hh:mm:ss", but how to convert it to "-mm-dd"? The datasets are txt
>> > files, not from excel.
>>
>> Use: as.Date
>> >
>> > On Fri, Dec 30, 2016 at 3:01 PM, Duncan Mackay 
>> wrote:
>> >
>> >> Hi
>> >>
>> >> Is this the output from Excel?
>> >> If so format it in Excel for a date format not a date-time format .
>> >> Depending how the dates were inputted into Excel and the Excel setup a
>> date
>> >> may not be a date format.
>> >> There are no rules with microsoft formatting so beware!
>> >>
>> >>
>> >> Regards
>> >>
>> >> Duncan
>> >>
>> >> Duncan Mackay
>> >> Department of Agronomy and Soil Science
>> >> University of New England
>> >> Armidale NSW 2351
>> >> Email: home: mac...@northnet.com.au
>> >>
>> >> -Original Message-
>> >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily
>> li
>> >> Sent: Saturday, 31 December 2016 05:38
>> >> To: Rui Barradas
>> >> Cc: R mailing list
>> >> Subject: Re: [R] about data format in R
>> >>
>> >> Hi Rui,
>> >>
>> >> Thanks for your reply. When I read in data using my code, the first
>> column
>> >> ranges from 0 to 1. So when I use the code you wrote, it shows the
>> error
>> >> message:
>> >> Error in as.POSIXct.numeric(DF$Date, format = "%m/%d/%Y-%H:%M:%S") :
>> >> 'origin' must be supplied
>> >>
>> >>
>> >> On Fri, Dec 30, 2016 at 11:23 AM, Rui Barradas 
>> >> wrote:
>> >>
>> >>> Hello,
>> >>>
>> >>> Have you tried
>> >>>
>> >>> df$date <- as.POSIXct(dat$date, format = "%m/%d/%Y-%H:%M:%S")
>> >>>
>> >>> ?
>> >>>
>> >>> Hope this helps,
>> >>>
>> >>> Rui Barradas
>> >>>
>> >>>
>> >>>
>> >>> Em 30-12-2016 17:40, lily li escreveu:
>> >>>
>> >>>> Hi R users,
>> >>>>
>> >>>> I'm trying to read in data, and then plot time series data. However,
>> I
>> >>>> have
>> >>>> some problems. In my dataset, the first column represents time, and
>> in
>> >> the
>> >>>> format:
>> >>>> mm/dd/-hr:min:sec; For example, 10/01/1995-00:00:00,
>> >>>> 10/01/1995-06:00:00, etc.
>> >>>>
>> >>>> df:
>> >>>>dateevap precipintercept
>> >>>> 10/01/1995-00:00:00   1.5  20.2
>> >>>> 10/01/1995-12:00:00   1.7  2.2 0.1
>> >>>> 10/02/1995-00:00:00   1.5  1.8 0.3
>> >>>> ...
>> >>>>
>> >>>> My code is like this
>> >>>> file1 = read.table('df', head=T)
>> >>>>
>> >>>> When I read in data, I found that it read incorrectly. How to format
>> >> when
>> >>>> read in data? Thanks.
>> >>>>
>> >>>>[[alternative HTML version deleted]]
>> >>>>
>> >>>> __
>> >>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> >>>> https://stat.ethz.ch/mailman/listinfo/r-help
>> >>>> PLEASE do read the posting guide http://www.R-project.org/posti
>> >>>> ng-guide.html
>> >>>> and provide commented, minimal, self-contained, reproducible code.
>> >>>>

Re: [R] about data format in R

2016-12-31 Thread lily li
I tried it, but it doesn't work. The time column is blank then.
DF$time = substring(DF$time, first=as.Date('1999-01-01),
last=as.Date('2005-12-30'))

On Sat, Dec 31, 2016 at 10:52 AM, David Winsemius 
wrote:

>
> > On Dec 31, 2016, at 9:26 AM, lily li  wrote:
> >
> > Hi all,
> >
> > Thanks for your help. Now I can convert data to the format "-mm-dd
> > hh:mm:ss", but how to convert it to "-mm-dd"? The datasets are txt
> > files, not from excel.
>
> Use: as.Date
> >
> > On Fri, Dec 30, 2016 at 3:01 PM, Duncan Mackay 
> wrote:
> >
> >> Hi
> >>
> >> Is this the output from Excel?
> >> If so format it in Excel for a date format not a date-time format .
> >> Depending how the dates were inputted into Excel and the Excel setup a
> date
> >> may not be a date format.
> >> There are no rules with microsoft formatting so beware!
> >>
> >>
> >> Regards
> >>
> >> Duncan
> >>
> >> Duncan Mackay
> >> Department of Agronomy and Soil Science
> >> University of New England
> >> Armidale NSW 2351
> >> Email: home: mac...@northnet.com.au
> >>
> >> -Original Message-
> >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
> >> Sent: Saturday, 31 December 2016 05:38
> >> To: Rui Barradas
> >> Cc: R mailing list
> >> Subject: Re: [R] about data format in R
> >>
> >> Hi Rui,
> >>
> >> Thanks for your reply. When I read in data using my code, the first
> column
> >> ranges from 0 to 1. So when I use the code you wrote, it shows the error
> >> message:
> >> Error in as.POSIXct.numeric(DF$Date, format = "%m/%d/%Y-%H:%M:%S") :
> >> 'origin' must be supplied
> >>
> >>
> >> On Fri, Dec 30, 2016 at 11:23 AM, Rui Barradas 
> >> wrote:
> >>
> >>> Hello,
> >>>
> >>> Have you tried
> >>>
> >>> df$date <- as.POSIXct(dat$date, format = "%m/%d/%Y-%H:%M:%S")
> >>>
> >>> ?
> >>>
> >>> Hope this helps,
> >>>
> >>> Rui Barradas
> >>>
> >>>
> >>>
> >>> Em 30-12-2016 17:40, lily li escreveu:
> >>>
> >>>> Hi R users,
> >>>>
> >>>> I'm trying to read in data, and then plot time series data. However, I
> >>>> have
> >>>> some problems. In my dataset, the first column represents time, and in
> >> the
> >>>> format:
> >>>> mm/dd/-hr:min:sec; For example, 10/01/1995-00:00:00,
> >>>> 10/01/1995-06:00:00, etc.
> >>>>
> >>>> df:
> >>>>dateevap precipintercept
> >>>> 10/01/1995-00:00:00   1.5  20.2
> >>>> 10/01/1995-12:00:00   1.7  2.2 0.1
> >>>> 10/02/1995-00:00:00   1.5  1.8 0.3
> >>>> ...
> >>>>
> >>>> My code is like this
> >>>> file1 = read.table('df', head=T)
> >>>>
> >>>> When I read in data, I found that it read incorrectly. How to format
> >> when
> >>>> read in data? Thanks.
> >>>>
> >>>>[[alternative HTML version deleted]]
> >>>>
> >>>> __
> >>>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >>>> https://stat.ethz.ch/mailman/listinfo/r-help
> >>>> PLEASE do read the posting guide http://www.R-project.org/posti
> >>>> ng-guide.html
> >>>> and provide commented, minimal, self-contained, reproducible code.
> >>>>
> >>>>
> >>
> >>[[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide http://www.R-project.org/
> >> posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide http://www.R-project.org/
> >> posting-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >
> >   [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>
> David Winsemius
> Alameda, CA, USA
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about data format in R

2016-12-31 Thread lily li
Thanks. It seems that substrings only subset the data, not convert the
format. For example, I use the code below:
DF$time = substring(DF$time, '%Y-%m-%d')

where DF$time has the structure:
'2002-01-01 00:00:00', '2002-01-01 12:00:00', '2003-01-01 00:00:00',
'2003-01-01 12:00:00', etc.
I wanted to convert the 'time' column to '2002-01-01', '2002-01-01',
'2003-01-01', '2003-01-01', etc.

Using the code above, it gives the error message:
Error in as.POSIXlt.character(as.character(x), ...) :
  character string is not in a standard unambiguous format

On Sat, Dec 31, 2016 at 10:36 AM, Bert Gunter 
wrote:

> ?substring
>
> (among others)
>
> -- Bert
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along
> and sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>
>
> On Sat, Dec 31, 2016 at 9:26 AM, lily li  wrote:
> > Hi all,
> >
> > Thanks for your help. Now I can convert data to the format "-mm-dd
> > hh:mm:ss", but how to convert it to "-mm-dd"? The datasets are txt
> > files, not from excel.
> >
> > On Fri, Dec 30, 2016 at 3:01 PM, Duncan Mackay 
> wrote:
> >
> >> Hi
> >>
> >> Is this the output from Excel?
> >> If so format it in Excel for a date format not a date-time format .
> >> Depending how the dates were inputted into Excel and the Excel setup a
> date
> >> may not be a date format.
> >> There are no rules with microsoft formatting so beware!
> >>
> >>
> >> Regards
> >>
> >> Duncan
> >>
> >> Duncan Mackay
> >> Department of Agronomy and Soil Science
> >> University of New England
> >> Armidale NSW 2351
> >> Email: home: mac...@northnet.com.au
> >>
> >> -Original Message-
> >> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
> >> Sent: Saturday, 31 December 2016 05:38
> >> To: Rui Barradas
> >> Cc: R mailing list
> >> Subject: Re: [R] about data format in R
> >>
> >> Hi Rui,
> >>
> >> Thanks for your reply. When I read in data using my code, the first
> column
> >> ranges from 0 to 1. So when I use the code you wrote, it shows the error
> >> message:
> >> Error in as.POSIXct.numeric(DF$Date, format = "%m/%d/%Y-%H:%M:%S") :
> >> 'origin' must be supplied
> >>
> >>
> >> On Fri, Dec 30, 2016 at 11:23 AM, Rui Barradas 
> >> wrote:
> >>
> >> > Hello,
> >> >
> >> > Have you tried
> >> >
> >> > df$date <- as.POSIXct(dat$date, format = "%m/%d/%Y-%H:%M:%S")
> >> >
> >> > ?
> >> >
> >> > Hope this helps,
> >> >
> >> > Rui Barradas
> >> >
> >> >
> >> >
> >> > Em 30-12-2016 17:40, lily li escreveu:
> >> >
> >> >> Hi R users,
> >> >>
> >> >> I'm trying to read in data, and then plot time series data. However,
> I
> >> >> have
> >> >> some problems. In my dataset, the first column represents time, and
> in
> >> the
> >> >> format:
> >> >> mm/dd/-hr:min:sec; For example, 10/01/1995-00:00:00,
> >> >> 10/01/1995-06:00:00, etc.
> >> >>
> >> >> df:
> >> >> dateevap precipintercept
> >> >> 10/01/1995-00:00:00   1.5  20.2
> >> >> 10/01/1995-12:00:00   1.7  2.2 0.1
> >> >> 10/02/1995-00:00:00   1.5  1.8 0.3
> >> >> ...
> >> >>
> >> >> My code is like this
> >> >> file1 = read.table('df', head=T)
> >> >>
> >> >> When I read in data, I found that it read incorrectly. How to format
> >> when
> >> >> read in data? Thanks.
> >> >>
> >> >> [[alternative HTML version deleted]]
> >> >>
> >> >> __
> >> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> >> PLEASE do read the posting guide http://www.R-project.org/posti
> >> 

Re: [R] about data format in R

2016-12-31 Thread lily li
Hi all,

Thanks for your help. Now I can convert data to the format "-mm-dd
hh:mm:ss", but how to convert it to "-mm-dd"? The datasets are txt
files, not from excel.

On Fri, Dec 30, 2016 at 3:01 PM, Duncan Mackay  wrote:

> Hi
>
> Is this the output from Excel?
> If so format it in Excel for a date format not a date-time format .
> Depending how the dates were inputted into Excel and the Excel setup a date
> may not be a date format.
> There are no rules with microsoft formatting so beware!
>
>
> Regards
>
> Duncan
>
> Duncan Mackay
> Department of Agronomy and Soil Science
> University of New England
> Armidale NSW 2351
> Email: home: mac...@northnet.com.au
>
> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
> Sent: Saturday, 31 December 2016 05:38
> To: Rui Barradas
> Cc: R mailing list
> Subject: Re: [R] about data format in R
>
> Hi Rui,
>
> Thanks for your reply. When I read in data using my code, the first column
> ranges from 0 to 1. So when I use the code you wrote, it shows the error
> message:
> Error in as.POSIXct.numeric(DF$Date, format = "%m/%d/%Y-%H:%M:%S") :
> 'origin' must be supplied
>
>
> On Fri, Dec 30, 2016 at 11:23 AM, Rui Barradas 
> wrote:
>
> > Hello,
> >
> > Have you tried
> >
> > df$date <- as.POSIXct(dat$date, format = "%m/%d/%Y-%H:%M:%S")
> >
> > ?
> >
> > Hope this helps,
> >
> > Rui Barradas
> >
> >
> >
> > Em 30-12-2016 17:40, lily li escreveu:
> >
> >> Hi R users,
> >>
> >> I'm trying to read in data, and then plot time series data. However, I
> >> have
> >> some problems. In my dataset, the first column represents time, and in
> the
> >> format:
> >> mm/dd/-hr:min:sec; For example, 10/01/1995-00:00:00,
> >> 10/01/1995-06:00:00, etc.
> >>
> >> df:
> >> dateevap precipintercept
> >> 10/01/1995-00:00:00   1.5  20.2
> >> 10/01/1995-12:00:00   1.7  2.2 0.1
> >> 10/02/1995-00:00:00   1.5  1.8 0.3
> >> ...
> >>
> >> My code is like this
> >> file1 = read.table('df', head=T)
> >>
> >> When I read in data, I found that it read incorrectly. How to format
> when
> >> read in data? Thanks.
> >>
> >> [[alternative HTML version deleted]]
> >>
> >> __
> >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> >> https://stat.ethz.ch/mailman/listinfo/r-help
> >> PLEASE do read the posting guide http://www.R-project.org/posti
> >> ng-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >>
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/
> posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] about data format in R

2016-12-30 Thread lily li
Hi Rui,

Thanks for your reply. When I read in data using my code, the first column
ranges from 0 to 1. So when I use the code you wrote, it shows the error
message:
Error in as.POSIXct.numeric(DF$Date, format = "%m/%d/%Y-%H:%M:%S") :
'origin' must be supplied


On Fri, Dec 30, 2016 at 11:23 AM, Rui Barradas  wrote:

> Hello,
>
> Have you tried
>
> df$date <- as.POSIXct(dat$date, format = "%m/%d/%Y-%H:%M:%S")
>
> ?
>
> Hope this helps,
>
> Rui Barradas
>
>
>
> Em 30-12-2016 17:40, lily li escreveu:
>
>> Hi R users,
>>
>> I'm trying to read in data, and then plot time series data. However, I
>> have
>> some problems. In my dataset, the first column represents time, and in the
>> format:
>> mm/dd/-hr:min:sec; For example, 10/01/1995-00:00:00,
>> 10/01/1995-06:00:00, etc.
>>
>> df:
>> dateevap precipintercept
>> 10/01/1995-00:00:00   1.5  20.2
>> 10/01/1995-12:00:00   1.7  2.2 0.1
>> 10/02/1995-00:00:00   1.5  1.8 0.3
>> ...
>>
>> My code is like this
>> file1 = read.table('df', head=T)
>>
>> When I read in data, I found that it read incorrectly. How to format when
>> read in data? Thanks.
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] about data format in R

2016-12-30 Thread lily li
Hi R users,

I'm trying to read in data, and then plot time series data. However, I have
some problems. In my dataset, the first column represents time, and in the
format:
mm/dd/-hr:min:sec; For example, 10/01/1995-00:00:00,
10/01/1995-06:00:00, etc.

df:
   dateevap precipintercept
10/01/1995-00:00:00   1.5  20.2
10/01/1995-12:00:00   1.7  2.2 0.1
10/02/1995-00:00:00   1.5  1.8 0.3
...

My code is like this
file1 = read.table('df', head=T)

When I read in data, I found that it read incorrectly. How to format when
read in data? Thanks.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] about data manipulation

2016-11-30 Thread lily li
Hi R users,

I'm trying to manipulate dataset, but met some difficulties.

df
year   month   flow
2006 33.5
2006 43.8
2006 521
2006 632
2007 34.1
2007 44.4
...

I want to calculate total flow for each year, and use the code below:
aggregate(flow~year, data=df, sum)
But it gave the error message:
Error in get(as.character(FUN), mode = "function", envir = envir) :
  object 'FUN' of mode 'function' was not found

What is the problem and how to solve it? Thanks for your help.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] About data manipulation

2016-11-26 Thread lily li
Thanks Jim, this method is very convenient and is what I want. Could I know
how to save the resulted dataframe? It printed in the console directly.

On Sat, Nov 26, 2016 at 5:55 PM, jim holtman  wrote:

> You did not provide any data, but I will take a stab at it using the
> "dplyr" package
>
> library(dplyr)
> DT %>%
> group_by(month, id, note) %>%
> summarise(avg = mean(total))
>
>
>
> Jim Holtman
> Data Munger Guru
>
> What is the problem that you are trying to solve?
> Tell me what you want to do, not how you want to do it.
>
> On Sat, Nov 26, 2016 at 11:11 AM, lily li  wrote:
>
>> Hi R users,
>>
>> I'm trying to manipulate a dataframe and have some difficulties.
>>
>> The original dataset is like this:
>>
>> DF
>> year   month   total   id note
>> 2000 1 98GA   1
>> 2001 1100   GA   1
>> 2002 2 99GA   1
>> 2002 2 80GB   1
>> ...
>> 2012 1 78GA   2
>> ...
>>
>> The structure is like this: when year is between 2000-2005, note is 1;
>> when
>> year is between 2006-2010, note is 2; GA, GB, etc represent different
>> groups, but they all have years 2000-2005, 2006-2010, 2011-2015.
>> I want to calculate one average value for each month in each time slice.
>> For example, between 2000-2005, when note is 1, for GA, there is one value
>> in month 1, one value in month 2, etc; for GB, there is one value in month
>> 1, one value in month 2, between this time period. So later, there is no
>> 'year' column, but other columns.
>> I tried the script: DF_GA = aggregate(total~year+month,data=subset(DF,
>> id==GA¬e==1)), but it did not give me the ideal dataframe. How to do
>> then?
>> Thanks for your help.
>>
>> [[alternative HTML version deleted]]
>>
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] About data manipulation

2016-11-26 Thread lily li
Hi R users,

I'm trying to manipulate a dataframe and have some difficulties.

The original dataset is like this:

DF
year   month   total   id note
2000 1 98GA   1
2001 1100   GA   1
2002 2 99GA   1
2002 2 80GB   1
...
2012 1 78GA   2
...

The structure is like this: when year is between 2000-2005, note is 1; when
year is between 2006-2010, note is 2; GA, GB, etc represent different
groups, but they all have years 2000-2005, 2006-2010, 2011-2015.
I want to calculate one average value for each month in each time slice.
For example, between 2000-2005, when note is 1, for GA, there is one value
in month 1, one value in month 2, etc; for GB, there is one value in month
1, one value in month 2, between this time period. So later, there is no
'year' column, but other columns.
I tried the script: DF_GA = aggregate(total~year+month,data=subset(DF,
id==GA¬e==1)), but it did not give me the ideal dataframe. How to do
then?
Thanks for your help.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] Read in files in r

2016-11-08 Thread lily li
Hi R users,

In the current directory, there are several folders (such as fold1, fold2,
fold3, etc.), while each folder includes the same named files, such as
file1.txt, file2.txt, file3.txt, etc. The structures of each folder and
each file are the same, but with different values. I want to read the files
from each folder, but can't get it to work. Could you please tell me why?
Thanks.

rd1 = read.table(file=list.files('fold1')[1], head=T)
rd2 = read.table(file=list.files('fold1')[2], head=T)

rt1 = read.table(file=list.files('fold2')[1], head=T)
rt2 = read.table(file=list.files('fold2')[2], head=T)

Then there are the warning sign that 'cannot open file 'file1.txt': No such
file or directory'

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] about data structure

2016-11-07 Thread lily li
Hi R users,

I'm wondering why the values changed when I try to transform factors into
numerics.

For example, for a data frame DF, there is one column called precipitation,
which is usually lower than 100mm. But this column is factor when I read in
the data. When transform to numeric values, some rows can be higher than
1000mm. What is the problem? Thanks.

DF$prec_new = as.numeric(DF$precip)

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] How to calculate row means while ignore NAs

2016-10-28 Thread lily li
My apologize, it has been solved. Just include w inside of select, such as:
select = c(w, x, y)

On Fri, Oct 28, 2016 at 12:06 PM, lily li  wrote:

> Hi R users,
>
> I have the dataframe as below:
>
> w=c(5,6,7,8)
> x=c(1,2,3,4)
> y=c(1,2,3)
> length(y)=4
> z=data.frame(w,x,y)
>
> z$mean1 <- rowMeans(subset(z, select = c(x, y)), na.rm = T)
> z$mean2 <- rowMeans(subset(z, select = c(x, y)), na.rm=F)
>
>   w x  y mean1 mean2
> 1 5 1  1 1 1
> 2 6 2  2 2 2
> 3 7 3  3 3 3
> 4 8 4 NA 4NA
>
> How to calculate mean value for the three columns, while default removing
> NAs.
> For example, for the fourth row, the mean value should be (8+4)/2 = 6
>
> Thanks for your help.
>

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] How to calculate row means while ignore NAs

2016-10-28 Thread lily li
Hi R users,

I have the dataframe as below:

w=c(5,6,7,8)
x=c(1,2,3,4)
y=c(1,2,3)
length(y)=4
z=data.frame(w,x,y)

z$mean1 <- rowMeans(subset(z, select = c(x, y)), na.rm = T)
z$mean2 <- rowMeans(subset(z, select = c(x, y)), na.rm=F)

  w x  y mean1 mean2
1 5 1  1 1 1
2 6 2  2 2 2
3 7 3  3 3 3
4 8 4 NA 4NA

How to calculate mean value for the three columns, while default removing
NAs.
For example, for the fourth row, the mean value should be (8+4)/2 = 6

Thanks for your help.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] About converting files in R

2016-10-25 Thread lily li
Hi R users,

Do any of you have any experience about converting binary files to ascii or
txt files in R? Thanks a lot for your help.

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


  1   2   >