[R] Problems with Mann-Kendall trend test

2016-06-17 Thread lily li
Dear R users,

Can anyone help me with mann-kendall trend test? I tried to use the newest
packages 'trend', and the function mk.test, but had problems in applying
the input data.

For example, res <- mk.test(Nile), Nile is a time-series data. But when I
use my dataset, with one column which is a time-series data, it says
"error: input must be ts object". How to do this? 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 change columns for specific rows

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

I have a data frame, and I generate a date column like this:
df$date = seq(as.Date('2012-01-01'), as.Date('2014-12-31'))

df
A  B  C
1  2   1
2  2   3
3  2   4

So the data frame has 4 columns now. But when I want to change the values
of column A for specific dates, such as 2012-01-01 to 2013-12-31, I use the
code below:
df[date >= '2012-01-01' <= '2013-12-31']$A =
df[date >= '2012-01-01' <= '2013-12-31']$A +2

But it does not work, the date I generate seems not effective. What is the
problem? 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 interpolating data in r

2016-07-22 Thread lily li
Thanks, Ismail.
For the gaps before 2009-01-05 and after 2009-11-20, I use the year 2010 to
fill in the missing values for column C. There is no relationship between
column A, B, and C.
For the missing values between 2009-01-05 and 2009-11-20, if there are any,
I found this approach is very helpful.
with(df, approx(x=time, y=C, xout=seq(min(time), max(time), by="days")))



On Thu, Jul 21, 2016 at 5:14 PM, Ismail SEZEN <sezenism...@gmail.com> wrote:

>
> > On 22 Jul 2016, at 01:34, lily li <chocol...@gmail.com> wrote:
> >
> > I have a question about interpolating missing values in a dataframe.
>
> First of all, filling missing values action must be taken into account
> very carefully. It must be known the nature of the data that wanted to be
> filled and most of the time, to let them be NA is the most appropriate
> action.
>
> > The
> > dataframe is in the following, Column C has no data before 2009-01-05 and
> > after 2009-12-31, how to interpolate data for the blanks?
>
> Why a dataframe? Is there any relationship between columns A,B and C? If
> there is, then you might want to consider filling missing values by a
> linear model approach instead of interpolation. You said that there is not
> data before 2009-01-05 and after 2009-12-31 but according to dataframe,
> there is not data after 2009-11-20?
>
> > That is to say,
> > interpolate linearly between these two gaps using 5.4 and 6.1? Thanks.
>
> Also you metion interpolating blanks but you want interpolation between
> two gaps? Do you want to fill missing values before 2009-01-05 and after
> 2009-11-20 or do you want to find intermediate values between 2009-01-05
> and 2009-11-20? This is a bit unclear.
>
> >
> >
> > df
> > timeA  B C
> > 2009-01-013  4.5
> > 2009-01-024  5
> > 2009-01-033.3   6
> > 2009-01-044.1   7
> > 2009-01-054.4   6.2   5.4
> > ...
> >
> > 2009-11-205.1   5.5   6.1
> > 2009-11-215.4   4
> > ...
> > 2009-12-314.5   6
>
>
> If you want to fill missing values at the end-points for column C (before
> 2009-01-05 and after 2009-11-20), and all data you have is between
> 2009-01-05 and 2009-11-20, this means that you want extrapolation (guessing
> unkonwn values that is out of known values). So, you can use only values at
> column C to guess missing end-point values. You can use splinefun (or
> spline) functions for this purpose. But let me note that this kind of
> approach might help you only for a few missing values close to end-points.
> Otherwise, you might find yourself in a huge mistake.
>
> As I mentioned in my first sentence, If you have a relationship between
> all columns or you have data for column C for other years (for instance,
> assume that you have data for column C for 2007, 2008, and 2010 but not
> 2009) you may want to try a statistical approach to fill the missing values.
>
>
>

[[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 netcdf files

2016-07-25 Thread lily li
Hi all,

I have a problem in opening netcdf files. If one netcdf file contains
longitude, latitude, and daily precipitation. How to relate each
precipitation record to its associated location, and export them as csv
files? Thanks.

I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks for
any ideas.

[[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 netcdf files

2016-07-26 Thread lily li
How to read continuous daily precipitation at each grid cell, and then
export to a csv file? Later, there should be several csv files, each
represents daily precipitation data for one grid cell. Thanks a lot.

On Tue, Jul 26, 2016 at 2:52 PM, Roy Mendelssohn - NOAA Federal <
roy.mendelss...@noaa.gov> wrote:

> Hi Lily:
>
> I doubt the mail-list would pass through the netcdf file. Instead, could
> you do the following, and post the results:
>
> library(ncdf4
> pre1 = nc_open('sample_precip_daily.nc')
> str(pre1)
> nc_close(pre1)
>
> I have a feeling you haven't worked much with netcdf files. I will try to
> find a tutorial also to help you along.
>
> Thanks,
>
> -Roy
>
> > On Jul 26, 2016, at 12:07 PM, lily li <chocol...@gmail.com> wrote:
> >
> > Thanks for your reply. But it says "Error in (function (classes, fdef,
> > mtable)):
> > unable to find an inherited method for function 'brick' for signature
> > 'ncdf4' "
> >
> > The dataset is attached. It contains daily precipitation data for 20
> years,
> > within a rectangle, so that there are several grid points. I use the code
> > to open it, but don't know how to get csv files, while each file contains
> > continuous daily precipitation data for each grid cell.
> > pre1 = nc_open('sample_precip_daily.nc')
> > pre1
> > pre1_rd = ncvar_get(pre1, 'precipitation')
> > nc_close(pre1)
> >
> > Thanks for your help.
> >
> > On Tue, Jul 26, 2016 at 4:08 AM, Jon Skoien <jon.sko...@jrc.ec.europa.eu
> >
> > wrote:
> >
> >> You could try with the brick function from the raster package.
> >>
> >> bvar = brick(netcdfName)
> >>
> >> This uses the ncdf4 functions for opening and reading the netcdf, but
> >> makes it easier to extract data for each day:
> >>
> >> p1 = rasterToPoints(bvar[[1]])
> >> and write p1 to csv.
> >>
> >> Best,
> >> Jon
> >>
> >>
> >>
> >> On 7/26/2016 6:54 AM, lily li wrote:
> >>
> >>> Hi all,
> >>>
> >>> I have a problem in opening netcdf files. If one netcdf file contains
> >>> longitude, latitude, and daily precipitation. How to relate each
> >>> precipitation record to its associated location, and export them as csv
> >>> files? Thanks.
> >>>
> >>> I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks
> for
> >>> any ideas.
> >>>
> >>>[[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.
> >>>
> >>>
> >> --
> >> Jon Olav Skøien
> >> Joint Research Centre - European Commission
> >> Institute for Space, Security & Migration
> >> Disaster Risk Management Unit
> >>
> >> Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY
> >>
> >> jon.sko...@jrc.ec.europa.eu
> >> Tel:  +39 0332 789205
> >>
> >> Disclaimer: Views expressed in this email are those of the individual
> and
> >> do not necessarily represent official views of the European Commission.
> >>
> > __
> > 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.
>
> **
> "The contents of this message do not reflect any position of the U.S.
> Government or NOAA."
> **
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new address and phone***
> 110 Shaffer Road
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK
> Jr.
>
>

[[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 netcdf files

2016-07-26 Thread lily li
 : int 1
  .. .. .. ..$ dimvarid :List of 5
  .. .. .. .. ..$ id : int 2
  .. .. .. .. ..$ group_index: int 1
  .. .. .. .. ..$ group_id   : int 262144
  .. .. .. .. ..$ list_index : num -1
  .. .. .. .. ..$ isdimvar   : logi TRUE
  .. .. .. .. ..- attr(*, "class")= chr "ncid4"
  .. .. .. ..$ units: chr "degrees_north"
  .. .. .. ..$ vals : num [1:5(1d)] 39.8 39.9 40 40 40.1
  .. .. .. ..$ create_dimvar: logi TRUE
  .. .. .. ..- attr(*, "class")= chr "ncdim4"
  .. .. ..$ :List of 11
  .. .. .. ..$ name : chr "time"
  .. .. .. ..$ len  : int 7305
  .. .. .. ..$ unlim: logi FALSE
  .. .. .. ..$ group_index  : int 1
  .. .. .. ..$ group_id : int 262144
  .. .. .. ..$ id   : int 0
  .. .. .. ..$ dimvarid :List of 5
  .. .. .. .. ..$ id : int 1
  .. .. .. .. ..$ group_index: int 1
  .. .. .. .. ..$ group_id   : int 262144
  .. .. .. .. ..$ list_index : num -1
  .. .. .. .. ..$ isdimvar   : logi TRUE
  .. .. .. .. ..- attr(*, "class")= chr "ncid4"
  .. .. .. ..$ units: chr "days since 1900-01-01 00:00:00"
  .. .. .. ..$ calendar : chr "gregorian"
  .. .. .. ..$ vals : num [1:7305(1d)] 38716 38717 38718 38719
38720 ...
  .. .. .. ..$ create_dimvar: logi TRUE
  .. .. .. ..- attr(*, "class")= chr "ncdim4"
  .. ..$ varsize   : int [1:3] 9 5 7305
  .. ..$ unlim : logi FALSE
  .. ..$ make_missing_value: logi TRUE
  .. ..$ missval   : num -
  .. ..$ hasAddOffset  : logi FALSE
  .. ..$ hasScaleFact  : logi FALSE
  .. ..- attr(*, "class")= chr "ncvar4"
 - attr(*, "class")= chr "ncdf4"


On Tue, Jul 26, 2016 at 2:52 PM, Roy Mendelssohn - NOAA Federal <
roy.mendelss...@noaa.gov> wrote:

> Hi Lily:
>
> I doubt the mail-list would pass through the netcdf file. Instead, could
> you do the following, and post the results:
>
> library(ncdf4
> pre1 = nc_open('sample_precip_daily.nc')
> str(pre1)
> nc_close(pre1)
>
> I have a feeling you haven't worked much with netcdf files. I will try to
> find a tutorial also to help you along.
>
> Thanks,
>
> -Roy
>
> > On Jul 26, 2016, at 12:07 PM, lily li <chocol...@gmail.com> wrote:
> >
> > Thanks for your reply. But it says "Error in (function (classes, fdef,
> > mtable)):
> > unable to find an inherited method for function 'brick' for signature
> > 'ncdf4' "
> >
> > The dataset is attached. It contains daily precipitation data for 20
> years,
> > within a rectangle, so that there are several grid points. I use the code
> > to open it, but don't know how to get csv files, while each file contains
> > continuous daily precipitation data for each grid cell.
> > pre1 = nc_open('sample_precip_daily.nc')
> > pre1
> > pre1_rd = ncvar_get(pre1, 'precipitation')
> > nc_close(pre1)
> >
> > Thanks for your help.
> >
> > On Tue, Jul 26, 2016 at 4:08 AM, Jon Skoien <jon.sko...@jrc.ec.europa.eu
> >
> > wrote:
> >
> >> You could try with the brick function from the raster package.
> >>
> >> bvar = brick(netcdfName)
> >>
> >> This uses the ncdf4 functions for opening and reading the netcdf, but
> >> makes it easier to extract data for each day:
> >>
> >> p1 = rasterToPoints(bvar[[1]])
> >> and write p1 to csv.
> >>
> >> Best,
> >> Jon
> >>
> >>
> >>
> >> On 7/26/2016 6:54 AM, lily li wrote:
> >>
> >>> Hi all,
> >>>
> >>> I have a problem in opening netcdf files. If one netcdf file contains
> >>> longitude, latitude, and daily precipitation. How to relate each
> >>> precipitation record to its associated location, and export them as csv
> >>> files? Thanks.
> >>>
> >>> I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks
> for
> >>> any ideas.
> >>>
> >>>[[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.
> >>>
> >>>
> >> --
> >> Jon Olav Skøien
> >> Joint Research Centre - European Commission
> >> Institute for Space, Security & M

Re: [R] about netcdf files

2016-07-26 Thread lily li
Thanks for your reply. But it says "Error in (function (classes, fdef,
mtable)):
unable to find an inherited method for function 'brick' for signature
'ncdf4' "

The dataset is attached. It contains daily precipitation data for 20 years,
within a rectangle, so that there are several grid points. I use the code
to open it, but don't know how to get csv files, while each file contains
continuous daily precipitation data for each grid cell.
pre1 = nc_open('sample_precip_daily.nc')
pre1
pre1_rd = ncvar_get(pre1, 'precipitation')
nc_close(pre1)

Thanks for your help.

On Tue, Jul 26, 2016 at 4:08 AM, Jon Skoien <jon.sko...@jrc.ec.europa.eu>
wrote:

> You could try with the brick function from the raster package.
>
> bvar = brick(netcdfName)
>
> This uses the ncdf4 functions for opening and reading the netcdf, but
> makes it easier to extract data for each day:
>
> p1 = rasterToPoints(bvar[[1]])
> and write p1 to csv.
>
> Best,
> Jon
>
>
>
> On 7/26/2016 6:54 AM, lily li wrote:
>
>> Hi all,
>>
>> I have a problem in opening netcdf files. If one netcdf file contains
>> longitude, latitude, and daily precipitation. How to relate each
>> precipitation record to its associated location, and export them as csv
>> files? Thanks.
>>
>> I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks for
>> any ideas.
>>
>> [[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.
>>
>>
> --
> Jon Olav Skøien
> Joint Research Centre - European Commission
> Institute for Space, Security & Migration
> Disaster Risk Management Unit
>
> Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY
>
> jon.sko...@jrc.ec.europa.eu
> Tel:  +39 0332 789205
>
> Disclaimer: Views expressed in this email are those of the individual and
> do not necessarily represent official views of the European Commission.
>
__
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 column names for the matrix

2016-07-27 Thread lily li
Hi all,

I want to ask that how to create column names for a matrix. For example,
the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A, 2-B,
2-C, 2-D, 3-A, etc. Thanks for your help.

chars = c('A','B','C','D')
matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
k = 0
for(i in seq(1:length(1:5))){
  for(j in seq(1:length(chars))){
k = k+1
matrix1[,k] = c(1:100)[k]
  }
}

[[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 netcdf files

2016-07-27 Thread lily li
Hi Jon,

The versions are: raster_2.5-2 sp_1.2-3


On Wed, Jul 27, 2016 at 9:31 AM, Jon Skoien <jon.sko...@jrc.ec.europa.eu>
wrote:

> Hi Lily,
>
> You can ignore the first three lines, they are just for information.
> Which version of raster do you have? I see that the attempt to read the
> crs-variable was not wrapped in a try-call in earlier versions. Upgrading
> might help.
>
> Best,
> Jon
>
>
>
> On 7/27/2016 5:13 PM, lily li wrote:
>
> Hi Jon,
>
> I still have problems. The brick function does not work well and I don't
> know where to check the problem. I put the error message below, thanks.
>
> > pre = brick("~/Downloads/sample_precip_daily.nc")
> [1] "vobjtovarid4: error #F: I could not find the requsted var (or dimvar)
> in the file!"
> [1] "var (or dimvar) name: crs"
> [1] "file name: /.../Downloads/sample_precip_daily.nc"
> Error in vobjtovarid4(nc, varid, allowdimvar = TRUE, verbose = verbose) :
>   Variable not found
>
>
> On Wed, Jul 27, 2016 at 1:10 AM, Jon Skoien <jon.sko...@jrc.ec.europa.eu>
> wrote:
>
>> I think you get the error because you passed the object from nc_open(),
>> you should rather pass the filename of the netCDF, so:
>>
>> pre = brick("sample_precip_daily.nc")
>> From the test-file, this gives you a RasterBrick-object with 5*9 pixels
>> and 7305 layers.
>> Then you can extract data.frames of each layer with:
>> dframe = rasterToPoints(pre[[1]])
>> where 1 is the first layer, or time series with:
>> tseries = pre[3,4]
>> where 3 and 4 are the pixels in x and y-direction.
>>
>> To write dframe to csv:
>> write.csv(dframe, filename = "csvfile.csv")
>> Check the function for more options.
>>
>> Hope this helps you a bit further.
>> Jon
>>
>>
>> On 7/26/2016 9:07 PM, lily li wrote:
>>
>> Thanks for your reply. But it says "Error in (function (classes, fdef,
>> mtable)):
>> unable to find an inherited method for function 'brick' for signature
>> 'ncdf4' "
>>
>> The dataset is attached. It contains daily precipitation data for 20
>> years, within a rectangle, so that there are several grid points. I use the
>> code to open it, but don't know how to get csv files, while each file
>> contains continuous daily precipitation data for each grid cell.
>> pre1 = nc_open('sample_precip_daily.nc')
>> pre1
>> pre1_rd = ncvar_get(pre1, 'precipitation')
>> nc_close(pre1)
>>
>> Thanks for your help.
>>
>> On Tue, Jul 26, 2016 at 4:08 AM, Jon Skoien <
>> <jon.sko...@jrc.ec.europa.eu>jon.sko...@jrc.ec.europa.eu> wrote:
>>
>>> You could try with the brick function from the raster package.
>>>
>>> bvar = brick(netcdfName)
>>>
>>> This uses the ncdf4 functions for opening and reading the netcdf, but
>>> makes it easier to extract data for each day:
>>>
>>> p1 = rasterToPoints(bvar[[1]])
>>> and write p1 to csv.
>>>
>>> Best,
>>> Jon
>>>
>>>
>>>
>>> On 7/26/2016 6:54 AM, lily li wrote:
>>>
>>>> Hi all,
>>>>
>>>> I have a problem in opening netcdf files. If one netcdf file contains
>>>> longitude, latitude, and daily precipitation. How to relate each
>>>> precipitation record to its associated location, and export them as csv
>>>> files? Thanks.
>>>>
>>>> I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks
>>>> for
>>>> any ideas.
>>>>
>>>> [[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>
>>>> http://www.R-project.org/posting-guide.html
>>>> and provide commented, minimal, self-contained, reproducible code.
>>>>
>>>>
>>> --
>>> Jon Olav Skøien
>>> Joint Research Centre - European Commission
>>> Institute for Space, Security & Migration
>>> Disaster Risk Management Unit
>>>
>>> Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY
>>>
>>> jon.sko...@jrc.ec.europa.eu
>>> Tel:  +39 0332 789205 <%2B39%200332%20789205>
>>>
>>> Disclaimer: Views exp

Re: [R] how to create column names for the matrix

2016-07-27 Thread lily li
Thanks. I shorten a more complex matrix to this example, but use the
original structure of the code. The original matrix has all characters
instead of 1:5.


On Wed, Jul 27, 2016 at 12:42 PM, Hervé Pagès <hpa...@fredhutch.org> wrote:

> On 07/27/2016 11:40 AM, Hervé Pagès wrote:
>
>> Hi,
>>
>> On 07/27/2016 11:17 AM, lily li wrote:
>>
>>> Hi all,
>>>
>>> I want to ask that how to create column names for a matrix. For example,
>>> the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A,
>>> 2-B,
>>> 2-C, 2-D, 3-A, etc. Thanks for your help.
>>>
>>> chars = c('A','B','C','D')
>>> matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
>>> k = 0
>>> for(i in seq(1:length(1:5))){
>>>   for(j in seq(1:length(chars))){
>>> k = k+1
>>> matrix1[,k] = c(1:100)[k]
>>>   }
>>> }
>>>
>>
>> Also how could you possibly use such level of code obfuscation to
>> perform such simple initialization of your matrix?
>>
>> My 1st advice would be that you slow down and take the time to compare
>> seq(1:length(1:5)) with 1:length(1:5) with 1:5. It will be a great
>> learning experience!
>>
>> As for initializing your matrix, what about doing
>>
>>   ncol <- 5 * length(chars)
>>   matrix1 <- matrix(seq_len(ncol), nrow=100, ncol=ncol, byrow=TRUE)
>>
>> instead?
>>
>> Then set the colnames with:
>>
>>   colnames(matrix1) <- paste(rep(1:5, length(chars)), chars, sep="-")
>>
>
> or maybe
>
>   colnames(matrix1) <- paste(rep(1:5, each=length(chars)), chars, sep="-")
>
> is what you're after.
>
> H.
>
>
>
>> Cheers,
>> H.
>>
>>
>>> [[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.
>>>
>>>
>>
> --
> Hervé Pagès
>
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
>
> E-mail: hpa...@fredhutch.org
> Phone:  (206) 667-5791
> Fax:(206) 667-1319
>

[[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 column names for the matrix

2016-07-27 Thread lily li
Thanks, this works. I thought the code should put in the for loop, but it
turns out an extra line.

On Wed, Jul 27, 2016 at 12:50 PM, <ruipbarra...@sapo.pt> wrote:

> Hello,
>
> Try
>
>
> chars = c('A','B','C','D')
> matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
> k = 0
> for(i in 1:length(1:5)){  # or more simply just for(i in 1:5)
>   for(j in 1:length(chars)){
> k = k+1
> matrix1[,k] = k
>   }
> }
> matrix1
> tmp <- expand.grid(chars, 1:5, stringsAsFactors = FALSE)
> nms <- paste(tmp[[2]], tmp[[1]], sep = "-")
> rm(tmp)
> colnames(matrix1) <- nms
>
> head(matrix1)
>
>
> Hope this helps,
>
> Rui Barradas
>
>
> Citando lily li <chocol...@gmail.com>:
>
> Hi all,
>
> I want to ask that how to create column names for a matrix. For example,
> the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A, 2-B,
> 2-C, 2-D, 3-A, etc. Thanks for your help.
>
> chars = c('A','B','C','D')
> matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
> k = 0
> for(i in seq(1:length(1:5))){
> for(j in seq(1:length(chars))){
>k = k+1
>matrix1[,k] = c(1:100)[k]
> }
> }
>
> [[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.htmland 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] how to create column names for the matrix

2016-07-27 Thread lily li
If replace 1:5 to char2 = c('east','west','south','north','central'), how
to put on column names with the original structure? Thanks again.


On Wed, Jul 27, 2016 at 12:40 PM, Hervé Pagès <hpa...@fredhutch.org> wrote:

> Hi,
>
>
> On 07/27/2016 11:17 AM, lily li wrote:
>
>> Hi all,
>>
>> I want to ask that how to create column names for a matrix. For example,
>> the matrix below, the column names should be: 1-A, 1-B, 1-C, 1-D, 2-A,
>> 2-B,
>> 2-C, 2-D, 3-A, etc. Thanks for your help.
>>
>> chars = c('A','B','C','D')
>> matrix1 = matrix(nrow = length(1:100), ncol = length(1:5)*length(chars))
>> k = 0
>> for(i in seq(1:length(1:5))){
>>   for(j in seq(1:length(chars))){
>> k = k+1
>> matrix1[,k] = c(1:100)[k]
>>   }
>> }
>>
>
> Also how could you possibly use such level of code obfuscation to
> perform such simple initialization of your matrix?
>
> My 1st advice would be that you slow down and take the time to compare
> seq(1:length(1:5)) with 1:length(1:5) with 1:5. It will be a great
> learning experience!
>
> As for initializing your matrix, what about doing
>
>   ncol <- 5 * length(chars)
>   matrix1 <- matrix(seq_len(ncol), nrow=100, ncol=ncol, byrow=TRUE)
>
> instead?
>
> Then set the colnames with:
>
>   colnames(matrix1) <- paste(rep(1:5, length(chars)), chars, sep="-")
>
> Cheers,
> H.
>
>
>> [[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.
>>
>>
> --
> Hervé Pagès
>
> Program in Computational Biology
> Division of Public Health Sciences
> Fred Hutchinson Cancer Research Center
> 1100 Fairview Ave. N, M1-B514
> P.O. Box 19024
> Seattle, WA 98109-1024
>
> E-mail: hpa...@fredhutch.org
> Phone:  (206) 667-5791
> Fax:(206) 667-1319
>

[[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 interpolating data in r

2016-07-21 Thread lily li
I have a question about interpolating missing values in a dataframe. The
dataframe is in the following, Column C has no data before 2009-01-05 and
after 2009-12-31, how to interpolate data for the blanks? That is to say,
interpolate linearly between these two gaps using 5.4 and 6.1? Thanks.


df
timeA  B C
2009-01-013  4.5
2009-01-024  5
2009-01-033.3   6
2009-01-044.1   7
2009-01-054.4   6.2   5.4
...

2009-11-205.1   5.5   6.1
2009-11-215.4   4
...
2009-12-314.5   6

[[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 interpolating data in r

2016-07-21 Thread lily li
Thanks, I meant if there are missing data at the beginning and end of a
dataframe, how to interpolate according to available data?

For example, the A column has missing values at the beginning and end, how
to interpolate linearly between 10 and 12 for the missing values?

df <- data.frame(A=c(NA, NA,10,11,12, NA),B=c(5,5,4,3,4,5),C=c(3.3,4,3,1.5,
2.2,4),time=as.Date(c("1990-01-01","1990-02-
07","1990-02-14","1990-02-28","1990-03-01","1990-03-20")))


On Thu, Jul 21, 2016 at 4:48 PM, William Dunlap <wdun...@tibco.com> wrote:

> Try approx(), as in:
>
> df <-
> data.frame(A=c(10,11,12),B=c(5,5,4),C=c(3.3,4,3),time=as.Date(c("1990-01-01","1990-02-07","1990-02-14")))
> with(df, approx(x=time, y=C, xout=seq(min(time), max(time), by="days")))
>
> Do you notice how one can copy and paste that example out of the
> mail an into R to see how it works?  It would help if your questions
> had that same property - show how the example data could be created.
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Thu, Jul 21, 2016 at 3:34 PM, lily li <chocol...@gmail.com> wrote:
>
>> I have a question about interpolating missing values in a dataframe. The
>> dataframe is in the following, Column C has no data before 2009-01-05 and
>> after 2009-12-31, how to interpolate data for the blanks? That is to say,
>> interpolate linearly between these two gaps using 5.4 and 6.1? Thanks.
>>
>>
>> df
>> timeA  B C
>> 2009-01-013  4.5
>> 2009-01-024  5
>> 2009-01-033.3   6
>> 2009-01-044.1   7
>> 2009-01-054.4   6.2   5.4
>> ...
>>
>> 2009-11-205.1   5.5   6.1
>> 2009-11-215.4   4
>> ...
>> 2009-12-314.5   6
>>
>> [[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] installing the lubricate package

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

I'm trying to download lubricate from this website, and then install it on
my mac.
https://github.com/hadley/lubridate

but it says windows version does not apply to mac. How to install the
package for mac? 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 expand the dataframe

2016-07-21 Thread lily li
I use this code, and it works. So has to set 'all=TRUE'.

merge(df, data.frame(time=seq(as.Date("1990-01-01"),
to=as.Date("1990-12-31"), by="days")), all=TRUE)


On Thu, Jul 21, 2016 at 9:22 AM, Daniel Nordlund <djnordl...@gmail.com>
wrote:

> On 7/20/2016 8:26 PM, lily li wrote:
>
>> Yes, I tried to create a dataframe and merge it with the shortened
>> dataframe. The resulting dataframe goes with the short one and truncates
>> the complete date column, so it does not work.
>>
>> On Wed, Jul 20, 2016 at 6:38 PM, David Winsemius <dwinsem...@comcast.net>
>> wrote:
>>
>>
>>> On Jul 20, 2016, at 1:31 PM, lily li <chocol...@gmail.com> wrote:
>>>>
>>>> Hi R users,
>>>>
>>>> I have a dataframe, where there is a column 'time' represents time
>>>> series
>>>> but is not complete. How to expand the dataframe so this column will
>>>>
>>> become
>>>
>>>> complete, where other columns with the newly added rows have NA values?
>>>> Thanks.
>>>>
>>>> df
>>>> A B C time
>>>> 105 3.3 1990-01-01
>>>> 115  4 1990-02-07
>>>> 124 3  1990-02-14
>>>> ...
>>>>
>>>
>>> Make a dataframe with a 'time' column using seq.Date and merge that
>>> dataframe with your df dataframe.
>>>
>>>
>>>>   [[alternative HTML version deleted]]
>>>>
>>>
>>> Really  isn't it time you learned how to send plain text. You've
>>> posted many questions on Rhelp.  It's really not that difficult on
>>> gmail. I
>>> also have a gmail account and have had no difficulty finding instructions
>>> on how to do it.
>>>
>>>
>>>> __
>>>> 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
>>>
>>>
>>>
>>
> Don't just say you tried to do the merge and it doesn't work.  At a
> minimum show us the ACTUAL code you used and give us any error messages you
> got or show us a portion of the results and explain why it is not what you
> expected.  If possible, give us a small amount of data using dput() so that
> we can "play along at home" (i.e. give us a reproducible example).
>
> Dan
>
> Daniel Nordlund
> Port Townsend, WA
>
>
>
> --
> Daniel Noredlund
> Bothell, WA USA
>
>
> __
> 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 file name

2016-07-28 Thread lily li
Thanks, but how to get the string like this:
"35.84375_-100.71875" use the minus sign instead of dot.

On Thu, Jul 28, 2016 at 2:38 PM, jim holtman <jholt...@gmail.com> wrote:

> just strip off the first character:
>
> > a
> [1] "X35.84375_.100.71875"
> > a.new <- sub("^.", '', a)
> > a.new
> [1] "35.84375_.100.71875"
> >
>
>
> 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 Thu, Jul 28, 2016 at 3:51 PM, lily li <chocol...@gmail.com> wrote:
>
>> Hi R users,
>>
>> I have a string for example 'X35.84375_.100.71875', and I have another
>> dataframe df that I want to export with the transformed string name
>> '35.84375_-100.71875' with no extension. How to do this in R? Thanks for
>> your help.
>>
>> a = 'X35.84375_.100.71875'
>> write.table(df, file='', row.names=F, col.names=F)
>>
>> [[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] plot many dfs in ggplot

2016-08-02 Thread lily li
Another question is, if I want to shade the range between the maximum and
minimum values for daily or annual values, how to do it? Thanks again.


On Tue, Aug 2, 2016 at 12:50 PM, lily li <chocol...@gmail.com> wrote:

> Hi all,
>
> I have another question. There are several dataframes, each has the same
> columns: time, varA, varB, varC, etc. If I want to plot time ~ varA of each
> dataframe, where different dataframe names use different colors. How to do
> this in ggplot? Thanks for your help.
>
> Right now, I tried to use the code below, but very laborious, and needs
> colors manually.
>
> fig1 = ggplot()+
> geom_path(data=df1, aes(x=time, y= varA, color= 'df1'))+
> geom_path(data=df2, aes(x=time, y= varA, color= 'df2'))+
> geom_path(data=df3, aes(x=time, y= varA, color= 'df3'))+
> ...
> scale_color_manual('', limits=c('df1', 'df2', 'df3', ...),
> values=c('blue', red', 'green', ...))
> show(fig1)
>
>
>

[[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 netcdf files

2016-08-01 Thread lily li
Hi all,

I can read the data, but how to plot it using ggplot or something? In this
case, x-axis should be longitude, and y-axis should be latitude. I tried to
plot using raster function, but the x and y axes are from 0 to 1.
Thanks again.

The code is like this:
pre1 = nc_open('sample_precip_daily.nc')
pre.3d = ncvar_get(pre1, 'precipitation')

require(raster)
rplot = t(pre.3d[, , 1])
r = raster(rplot[nrow(rplot):1, ]
plot(r)


On Tue, Jul 26, 2016 at 1:07 PM, lily li <chocol...@gmail.com> wrote:

> Thanks for your reply. But it says "Error in (function (classes, fdef,
> mtable)):
> unable to find an inherited method for function 'brick' for signature
> 'ncdf4' "
>
> The dataset is attached. It contains daily precipitation data for 20
> years, within a rectangle, so that there are several grid points. I use the
> code to open it, but don't know how to get csv files, while each file
> contains continuous daily precipitation data for each grid cell.
> pre1 = nc_open('sample_precip_daily.nc')
> pre1
> pre1_rd = ncvar_get(pre1, 'precipitation')
> nc_close(pre1)
>
> Thanks for your help.
>
> On Tue, Jul 26, 2016 at 4:08 AM, Jon Skoien <jon.sko...@jrc.ec.europa.eu>
> wrote:
>
>> You could try with the brick function from the raster package.
>>
>> bvar = brick(netcdfName)
>>
>> This uses the ncdf4 functions for opening and reading the netcdf, but
>> makes it easier to extract data for each day:
>>
>> p1 = rasterToPoints(bvar[[1]])
>> and write p1 to csv.
>>
>> Best,
>> Jon
>>
>>
>>
>> On 7/26/2016 6:54 AM, lily li wrote:
>>
>>> Hi all,
>>>
>>> I have a problem in opening netcdf files. If one netcdf file contains
>>> longitude, latitude, and daily precipitation. How to relate each
>>> precipitation record to its associated location, and export them as csv
>>> files? Thanks.
>>>
>>> I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks for
>>> any ideas.
>>>
>>> [[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.
>>>
>>>
>> --
>> Jon Olav Skøien
>> Joint Research Centre - European Commission
>> Institute for Space, Security & Migration
>> Disaster Risk Management Unit
>>
>> Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY
>>
>> jon.sko...@jrc.ec.europa.eu
>> Tel:  +39 0332 789205
>>
>> Disclaimer: Views expressed in this email are those of the individual and
>> do not necessarily represent official views of the European Commission.
>>
>
>

[[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 annual values directly

2016-08-03 Thread lily li
I meant that my dataframe has daily data, but how to plot annual mean/sum
directly? Thanks.

On Wed, Aug 3, 2016 at 4:16 AM, PIKAL Petr <petr.pi...@precheza.cz> wrote:

> Hi
>
> What do you mean to plot annual mean/sum directly? You can compute it by
> aggregate function and add it to your plot, but I am not sure if it is
> enough direct.
>
> Cheers
> Petr
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
> > Sent: Tuesday, August 2, 2016 8:10 PM
> > To: R mailing list <r-help@r-project.org>
> > Subject: [R] how to plot annual values directly
> >
> > Hi R users,
> >
> > I have a dataframe, with daily precipitation data, is it possible to
> plot annual
> > mean or annual sum values directly? Thanks for your help.
> >
> > df
> > year   month   day   precip   time
> > 2010 1  10.5 2010-01-01
> > 2010 1  20.8 2010-01-02
> > 2010 1  31.0 2010-01-03
> > 2010 1  40.9 2010-01-04
> > ...
> >
> > fig1 = ggplot()+ geom_path(data=df, aes(x=time, y= precip)
> > show(fig1)
> >
> >   [[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 sender reserves the right to end negotiations about entering into a
> contract in any time, for any reason, and without stating any reasoning.
> - if the e-mail contains an offer, the recipient is entitled to
> immediately accept such offer; The sender of this e-mail (offer) excludes
> any acceptance of the offer on the part of the recipient containing any
> amendment or variation.
> - the sender insists on that the respective contract is concluded only
> upon an express mutual agreement on all its aspects.
> - the sender of this e-mail informs that he/she is not authorized to enter
> into any contracts on behalf of the company except for cases in which
> he/she is expressly authorized to do so in writing, and such authorization
> or power of attorney is submitted to the recipient or the person
> represented by the recipient, or the existence of such authorization is
> known to the recipient of the person represented by the recipient.
>

[[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] plot many dfs in ggplot

2016-08-03 Thread lily li
Thanks, but rbind/merge function only combines two dataframes each time,
how to work on multiple dataframes? Thanks again.


On Wed, Aug 3, 2016 at 4:20 AM, PIKAL Petr <petr.pi...@precheza.cz> wrote:

> Hi.
>
> Hm. I would add a column indicating data frame and merge/rbind all data
> frames.
>
> Something like
>
> df1$fr <- 1
> df2$fr <- 2
>
> dfkompl <- rbind(df1, df2)
>
> ggplot(dfkompl, aes(x=time, y=varA, colour=factor(fr))
>
> Cheers
> Petr
>
>
> > -Original Message-----
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily li
> > Sent: Tuesday, August 2, 2016 8:51 PM
> > To: R mailing list <r-help@r-project.org>
> > Subject: [R] plot many dfs in ggplot
> >
> > Hi all,
> >
> > I have another question. There are several dataframes, each has the same
> > columns: time, varA, varB, varC, etc. If I want to plot time ~ varA of
> each
> > dataframe, where different dataframe names use different colors. How to
> > do this in ggplot? Thanks for your help.
> >
> > Right now, I tried to use the code below, but very laborious, and needs
> colors
> > manually.
> >
> > fig1 = ggplot()+
> > geom_path(data=df1, aes(x=time, y= varA, color= 'df1'))+
> > geom_path(data=df2, aes(x=time, y= varA, color= 'df2'))+
> > geom_path(data=df3, aes(x=time, y= varA, color= 'df3'))+
> > ...
> > scale_color_manual('', limits=c('df1', 'df2', 'df3', ...),
> values=c('blue', red',
> > 'green', ...))
> > show(fig1)
> >
> >   [[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 sender reserves the right to end negotiations about entering into a
> contract in any time, for any reason, and without stating any reasoning.
> - if the e-mail contains an offer, the recipient is entitled to
> immediately accept such offer; The sender of this e-mail (offer) excludes
> any acceptance of the offer on the part of the recipient containing any
> amendment or variation.
> - the sender insists on that the respective contract is concluded only
> upon an express mutual agreement on all its aspects.
> - the sender of this e-mail informs that he/she is not authorized to enter
> into any contracts on behalf of the company except for cases

Re: [R] plot many dfs in ggplot

2016-08-03 Thread lily li
Thanks. How to add an additional column, with the name of each dataframe's
name?

On Wed, Aug 3, 2016 at 1:06 PM, Ulrik Stervbo <ulrik.ster...@gmail.com>
wrote:

> Not quite - this works: rbind(df1, df2, df3, df1, df2, df3)
>
> Or if the have your data.frames in a list, use do.call:
>
> df.lst <- list(df1, df2, df3, df1, df2, df3)
> do.call(rbind, df.lst)
>
> You might take a look at the facet functionality in ggplot once you are
> ready to build your plots.
>
> Best,
> Ulrik
>
> On Wed, 3 Aug 2016 at 17:42 lily li <chocol...@gmail.com> wrote:
>
>> Thanks, but rbind/merge function only combines two dataframes each time,
>> how to work on multiple dataframes? Thanks again.
>>
>>
>> On Wed, Aug 3, 2016 at 4:20 AM, PIKAL Petr <petr.pi...@precheza.cz>
>> wrote:
>>
>> > Hi.
>> >
>> > Hm. I would add a column indicating data frame and merge/rbind all data
>> > frames.
>> >
>> > Something like
>> >
>> > df1$fr <- 1
>> > df2$fr <- 2
>> >
>> > dfkompl <- rbind(df1, df2)
>> >
>> > ggplot(dfkompl, aes(x=time, y=varA, colour=factor(fr))
>> >
>> > Cheers
>> > Petr
>> >
>> >
>> > > -Original Message-
>> > > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of lily
>> li
>> > > Sent: Tuesday, August 2, 2016 8:51 PM
>> > > To: R mailing list <r-help@r-project.org>
>> > > Subject: [R] plot many dfs in ggplot
>> > >
>> > > Hi all,
>> > >
>> > > I have another question. There are several dataframes, each has the
>> same
>> > > columns: time, varA, varB, varC, etc. If I want to plot time ~ varA of
>> > each
>> > > dataframe, where different dataframe names use different colors. How
>> to
>> > > do this in ggplot? Thanks for your help.
>> > >
>> > > Right now, I tried to use the code below, but very laborious, and
>> needs
>> > colors
>> > > manually.
>> > >
>> > > fig1 = ggplot()+
>> > > geom_path(data=df1, aes(x=time, y= varA, color= 'df1'))+
>> > > geom_path(data=df2, aes(x=time, y= varA, color= 'df2'))+
>> > > geom_path(data=df3, aes(x=time, y= varA, color= 'df3'))+
>> > > ...
>> > > scale_color_manual('', limits=c('df1', 'df2', 'df3', ...),
>> > values=c('blue', red',
>> > > 'green', ...))
>> > > show(fig1)
>> > >
>> > >   [[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 zastupu

[R] how to expand the dataframe

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

I have a dataframe, where there is a column 'time' represents time series
but is not complete. How to expand the dataframe so this column will become
complete, where other columns with the newly added rows have NA values?
Thanks.

df
A B C time
105 3.3   1990-01-01
115  4 1990-02-07
124 3  1990-02-14
...

[[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 expand the dataframe

2016-07-20 Thread lily li
Yes, I tried to create a dataframe and merge it with the shortened
dataframe. The resulting dataframe goes with the short one and truncates
the complete date column, so it does not work.

On Wed, Jul 20, 2016 at 6:38 PM, David Winsemius <dwinsem...@comcast.net>
wrote:

>
> > On Jul 20, 2016, at 1:31 PM, lily li <chocol...@gmail.com> wrote:
> >
> > Hi R users,
> >
> > I have a dataframe, where there is a column 'time' represents time series
> > but is not complete. How to expand the dataframe so this column will
> become
> > complete, where other columns with the newly added rows have NA values?
> > Thanks.
> >
> > df
> > A B C time
> > 105 3.3 1990-01-01
> > 115  4 1990-02-07
> > 124 3  1990-02-14
> > ...
>
> Make a dataframe with a 'time' column using seq.Date and merge that
> dataframe with your df dataframe.
>
> >
> >   [[alternative HTML version deleted]]
>
> Really  isn't it time you learned how to send plain text. You've
> posted many questions on Rhelp.  It's really not that difficult on gmail. I
> also have a gmail account and have had no difficulty finding instructions
> on how to do it.
>
> >
> > __
> > 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 smwrgraphs package

2016-07-11 Thread lily li
I still haven't heard back from anyone. Please let me know as I think it is
better to discuss here.

On Sun, Jul 10, 2016 at 1:25 PM, lily li <chocol...@gmail.com> wrote:

> Has anyone used smwrGraphs package? I have some problems and think it may
> be better to discuss if you have been using it. 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] about smwrgraphs package

2016-07-10 Thread lily li
Has anyone used smwrGraphs package? I have some problems and think it may
be better to discuss if you have been using it. 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] plot many dfs in ggplot

2016-08-02 Thread lily li
Hi all,

I have another question. There are several dataframes, each has the same
columns: time, varA, varB, varC, etc. If I want to plot time ~ varA of each
dataframe, where different dataframe names use different colors. How to do
this in ggplot? Thanks for your help.

Right now, I tried to use the code below, but very laborious, and needs
colors manually.

fig1 = ggplot()+
geom_path(data=df1, aes(x=time, y= varA, color= 'df1'))+
geom_path(data=df2, aes(x=time, y= varA, color= 'df2'))+
geom_path(data=df3, aes(x=time, y= varA, color= 'df3'))+
...
scale_color_manual('', limits=c('df1', 'df2', 'df3', ...),
values=c('blue', red', 'green', ...))
show(fig1)

[[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 annual values directly

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

I have a dataframe, with daily precipitation data, is it possible to plot
annual mean or annual sum values directly? Thanks for your help.

df
year   month   day   precip   time
2010 1  10.5 2010-01-01
2010 1  20.8 2010-01-02
2010 1  31.0 2010-01-03
2010 1  40.9 2010-01-04
...

fig1 = ggplot()+ geom_path(data=df, aes(x=time, y= precip)
show(fig1)

[[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 netcdf files

2016-08-01 Thread lily li
Thanks, Roy. I will do a search. In addition, how to look at spatial
patterns from this netcdf file? Thanks again.

On Mon, Aug 1, 2016 at 11:46 AM, Roy Mendelssohn - NOAA Federal <
roy.mendelss...@noaa.gov> wrote:

> Hi Lily:
>
> If you download the vignette to my xtractomatic package  (
> http://coastwatch.pfeg.noaa.gov/xtracto/index.html) there are any number
> of examples using ggplot2 to make maps from netcdf data,
>
> HTH,
>
> -Roy
>
> > On Aug 1, 2016, at 10:35 AM, lily li <chocol...@gmail.com> wrote:
> >
> > Hi all,
> >
> > I can read the data, but how to plot it using ggplot or something? In
> this
> > case, x-axis should be longitude, and y-axis should be latitude. I tried
> to
> > plot using raster function, but the x and y axes are from 0 to 1.
> > Thanks again.
> >
> > The code is like this:
> > pre1 = nc_open('sample_precip_daily.nc')
> > pre.3d = ncvar_get(pre1, 'precipitation')
> >
> > require(raster)
> > rplot = t(pre.3d[, , 1])
> > r = raster(rplot[nrow(rplot):1, ]
> > plot(r)
> >
> >
> > On Tue, Jul 26, 2016 at 1:07 PM, lily li <chocol...@gmail.com> wrote:
> >
> >> Thanks for your reply. But it says "Error in (function (classes, fdef,
> >> mtable)):
> >> unable to find an inherited method for function 'brick' for signature
> >> 'ncdf4' "
> >>
> >> The dataset is attached. It contains daily precipitation data for 20
> >> years, within a rectangle, so that there are several grid points. I use
> the
> >> code to open it, but don't know how to get csv files, while each file
> >> contains continuous daily precipitation data for each grid cell.
> >> pre1 = nc_open('sample_precip_daily.nc')
> >> pre1
> >> pre1_rd = ncvar_get(pre1, 'precipitation')
> >> nc_close(pre1)
> >>
> >> Thanks for your help.
> >>
> >> On Tue, Jul 26, 2016 at 4:08 AM, Jon Skoien <
> jon.sko...@jrc.ec.europa.eu>
> >> wrote:
> >>
> >>> You could try with the brick function from the raster package.
> >>>
> >>> bvar = brick(netcdfName)
> >>>
> >>> This uses the ncdf4 functions for opening and reading the netcdf, but
> >>> makes it easier to extract data for each day:
> >>>
> >>> p1 = rasterToPoints(bvar[[1]])
> >>> and write p1 to csv.
> >>>
> >>> Best,
> >>> Jon
> >>>
> >>>
> >>>
> >>> On 7/26/2016 6:54 AM, lily li wrote:
> >>>
> >>>> Hi all,
> >>>>
> >>>> I have a problem in opening netcdf files. If one netcdf file contains
> >>>> longitude, latitude, and daily precipitation. How to relate each
> >>>> precipitation record to its associated location, and export them as
> csv
> >>>> files? Thanks.
> >>>>
> >>>> I just use nc_open(), ncvar_get(), but it is not very helpful. Thanks
> for
> >>>> any ideas.
> >>>>
> >>>>[[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.
> >>>>
> >>>>
> >>> --
> >>> Jon Olav Skøien
> >>> Joint Research Centre - European Commission
> >>> Institute for Space, Security & Migration
> >>> Disaster Risk Management Unit
> >>>
> >>> Via E. Fermi 2749, TP 122,  I-21027 Ispra (VA), ITALY
> >>>
> >>> jon.sko...@jrc.ec.europa.eu
> >>> Tel:  +39 0332 789205
> >>>
> >>> Disclaimer: Views expressed in this email are those of the individual
> and
> >>> do not necessarily represent official views of the European Commission.
> >>>
> >>
> >>
> >
> >   [[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.
>
> **
> "The contents of this message do not reflect any position of the U.S.
> Government or NOAA."
> **
> Roy Mendelssohn
> Supervisory Operations Research Analyst
> NOAA/NMFS
> Environmental Research Division
> Southwest Fisheries Science Center
> ***Note new address and phone***
> 110 Shaffer Road
> Santa Cruz, CA 95060
> Phone: (831)-420-3666
> Fax: (831) 420-3980
> e-mail: roy.mendelss...@noaa.gov www: http://www.pfeg.noaa.gov/
>
> "Old age and treachery will overcome youth and skill."
> "From those who have been given much, much will be expected"
> "the arc of the moral universe is long, but it bends toward justice" -MLK
> Jr.
>
>

[[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 file name

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

I have a string for example 'X35.84375_.100.71875', and I have another
dataframe df that I want to export with the transformed string name
'35.84375_-100.71875' with no extension. How to do this in R? Thanks for
your help.

a = 'X35.84375_.100.71875'
write.table(df, file='', row.names=F, col.names=F)

[[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] Merge several datasets into one

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

I'd like to ask that how to merge several datasets into one in R? I put
these csv files in one folder, and use the lapply function, but it says
that cannot open file 'xx.csv'. These files have different names, but end
with .csv extension, and the files have the same header. 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] regroup row names

2016-07-03 Thread lily li
I have a problem in changing row names in a dataframe in R. The first
column is ID, such as aClim_st02, aClim_st03, aClim_st 05, bClim_st01,
bClim_st02, etc. How to rename the names, so that aClim_ all grouped to
aClim, while bClim_ all grouped to bClim? Thanks for your help.
df

IDtemp   precip   LW   SW
aClim_st02
aClim_st03
aClim_st05
bClim_st01
bClim_st02
...

[[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] regroup row names

2016-07-03 Thread lily li
Hi Ulrik,

Thanks. This is for one group, but how to do for several groups? I tried
gsub(c(),c(),df$ID), but it does not work.


On Sun, Jul 3, 2016 at 12:24 PM, Ulrik Stervbo <ulrik.ster...@gmail.com>
wrote:

> Hi Lily,
>
> you can use gsub:
>
> df$ID <- gsub("_.*", "", df$ID)
>
> HTH
> Ulrik
>
> On Sun, 3 Jul 2016 at 20:16 lily li <chocol...@gmail.com> wrote:
>
>> I have a problem in changing row names in a dataframe in R. The first
>> column is ID, such as aClim_st02, aClim_st03, aClim_st 05, bClim_st01,
>> bClim_st02, etc. How to rename the names, so that aClim_ all grouped to
>> aClim, while bClim_ all grouped to bClim? Thanks for your help.
>> df
>>
>> IDtemp   precip   LW   SW
>> aClim_st02
>> aClim_st03
>> aClim_st05
>> bClim_st01
>> bClim_st02
>> ...
>>
>> [[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] 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 <drjimle...@gmail.com> 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 <chocol...@gmail.com> 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 data problem

2016-09-20 Thread lily li
I reread the data, and use 'na.rm = T' when reading the data. This time it
has no such problem. It seems that the existence of NAs convert the integer
to factor. Thanks for your help.


On Tue, Sep 20, 2016 at 4:09 PM, Jianling Fan <fanjianl...@gmail.com> wrote:

> Add the "stringsAsFactors = F"  when you read the data, and then
> convert them to numeric.
>
> On 20 September 2016 at 16:00, lily li <chocol...@gmail.com> wrote:
> > Yes, it is stored as factor. I can't check out any problem in the
> original
> > data. Reread data doesn't help either. I use read.csv to read in the
> data,
> > do you think it is better to use read.table? Thanks again.
> >
> > On Tue, Sep 20, 2016 at 3:55 PM, Greg Snow <538...@gmail.com> wrote:
> >
> >> This indicates that your Discharge column has been stored/converted as
> >> a factor (run str(df) to verify and check other columns).  This
> >> usually happens when functions like read.table are left to try to
> >> figure out what each column is and it finds something in that column
> >> that cannot be converted to a number (possibly an oh instead of a
> >> zero, an el instead of a one, or just a letter or punctuation mark
> >> accidentally in the file).  You can either find the error in your
> >> original data, fix it, and reread the data, or specify that the column
> >> should be numeric using the colClasses argument to read.table or other
> >> function.
> >>
> >>
> >>
> >> On Tue, Sep 20, 2016 at 3:46 PM, lily li <chocol...@gmail.com> wrote:
> >> > Hi R users,
> >> >
> >> > I have a problem in reading data.
> >> > For example, part of my dataframe is like this:
> >> >
> >> > df
> >> > month day year  Discharge
> >> >31   20106.4
> >> >32   2010   7.58
> >> >33   2010   6.82
> >> >34   2010   8.63
> >> >35   2010   8.16
> >> >36   2010   7.58
> >> >
> >> > Then if I type summary(df), why it converts the discharge data to
> >> levels? I
> >> > also met the same problem when reading some other csv files. How to
> solve
> >> > this problem? Thanks.
> >> >
> >> > Discharge
> >> > 7.58 :2
> >> > 6.4   :1
> >> > 6.82 :1
> >> > 8.63 :1
> >> > 8.16 :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.
> >>
> >>
> >>
> >> --
> >> Gregory (Greg) L. Snow Ph.D.
> >> 538...@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.
>
>
>
> --
> Jianling Fan
> 樊建凌
>

[[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 problem

2016-09-20 Thread lily li
Hi R users,

I have a problem in reading data.
For example, part of my dataframe is like this:

df
month day year  Discharge
   31   20106.4
   32   2010   7.58
   33   2010   6.82
   34   2010   8.63
   35   2010   8.16
   36   2010   7.58

Then if I type summary(df), why it converts the discharge data to levels? I
also met the same problem when reading some other csv files. How to solve
this problem? Thanks.

Discharge
7.58 :2
6.4   :1
6.82 :1
8.63 :1
8.16 :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 data problem

2016-09-20 Thread lily li
Thanks. Then what should I do to solve the problem?

On Tue, Sep 20, 2016 at 4:30 PM, Jeff Newmiller <jdnew...@dcn.davis.ca.us>
wrote:

> I suppose you can do what works for your data, but I wouldn't recommend
> na.rm=TRUE because it hides problems rather than clarifying them.
>
> If in fact your data includes true NA values (the letters NA or simply
> nothing between the commas are typical ways this information may be
> indicated), then read.csv will NOT change from integer to factor
> (particularly if you have specified which markers represent NA using the
> na.strings argument documented under read.table)... so you probably DO have
> unexpected garbage still in your data which could be obscuring valuable
> information that could affect your conclusions.
> --
> Sent from my phone. Please excuse my brevity.
>
> On September 20, 2016 3:11:42 PM PDT, lily li <chocol...@gmail.com> wrote:
> >I reread the data, and use 'na.rm = T' when reading the data. This time
> >it
> >has no such problem. It seems that the existence of NAs convert the
> >integer
> >to factor. Thanks for your help.
> >
> >
> >On Tue, Sep 20, 2016 at 4:09 PM, Jianling Fan <fanjianl...@gmail.com>
> >wrote:
> >
> >> Add the "stringsAsFactors = F"  when you read the data, and then
> >> convert them to numeric.
> >>
> >> On 20 September 2016 at 16:00, lily li <chocol...@gmail.com> wrote:
> >> > Yes, it is stored as factor. I can't check out any problem in the
> >> original
> >> > data. Reread data doesn't help either. I use read.csv to read in
> >the
> >> data,
> >> > do you think it is better to use read.table? Thanks again.
> >> >
> >> > On Tue, Sep 20, 2016 at 3:55 PM, Greg Snow <538...@gmail.com>
> >wrote:
> >> >
> >> >> This indicates that your Discharge column has been
> >stored/converted as
> >> >> a factor (run str(df) to verify and check other columns).  This
> >> >> usually happens when functions like read.table are left to try to
> >> >> figure out what each column is and it finds something in that
> >column
> >> >> that cannot be converted to a number (possibly an oh instead of a
> >> >> zero, an el instead of a one, or just a letter or punctuation mark
> >> >> accidentally in the file).  You can either find the error in your
> >> >> original data, fix it, and reread the data, or specify that the
> >column
> >> >> should be numeric using the colClasses argument to read.table or
> >other
> >> >> function.
> >> >>
> >> >>
> >> >>
> >> >> On Tue, Sep 20, 2016 at 3:46 PM, lily li <chocol...@gmail.com>
> >wrote:
> >> >> > Hi R users,
> >> >> >
> >> >> > I have a problem in reading data.
> >> >> > For example, part of my dataframe is like this:
> >> >> >
> >> >> > df
> >> >> > month day year  Discharge
> >> >> >31   20106.4
> >> >> >32   2010   7.58
> >> >> >33   2010   6.82
> >> >> >34   2010   8.63
> >> >> >35   2010   8.16
> >> >> >36   2010   7.58
> >> >> >
> >> >> > Then if I type summary(df), why it converts the discharge data
> >to
> >> >> levels? I
> >> >> > also met the same problem when reading some other csv files. How
> >to
> >> solve
> >> >> > this problem? Thanks.
> >> >> >
> >> >> > Discharge
> >> >> > 7.58 :2
> >> >> > 6.4   :1
> >> >> > 6.82 :1
> >> >> > 8.63 :1
> >> >> > 8.16 :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
&g

Re: [R] about data problem

2016-09-20 Thread lily li
Yes, it is stored as factor. I can't check out any problem in the original
data. Reread data doesn't help either. I use read.csv to read in the data,
do you think it is better to use read.table? Thanks again.

On Tue, Sep 20, 2016 at 3:55 PM, Greg Snow <538...@gmail.com> wrote:

> This indicates that your Discharge column has been stored/converted as
> a factor (run str(df) to verify and check other columns).  This
> usually happens when functions like read.table are left to try to
> figure out what each column is and it finds something in that column
> that cannot be converted to a number (possibly an oh instead of a
> zero, an el instead of a one, or just a letter or punctuation mark
> accidentally in the file).  You can either find the error in your
> original data, fix it, and reread the data, or specify that the column
> should be numeric using the colClasses argument to read.table or other
> function.
>
>
>
> On Tue, Sep 20, 2016 at 3:46 PM, lily li <chocol...@gmail.com> wrote:
> > Hi R users,
> >
> > I have a problem in reading data.
> > For example, part of my dataframe is like this:
> >
> > df
> > month day year  Discharge
> >31   20106.4
> >32   2010   7.58
> >33   2010   6.82
> >34   2010   8.63
> >35   2010   8.16
> >36   2010   7.58
> >
> > Then if I type summary(df), why it converts the discharge data to
> levels? I
> > also met the same problem when reading some other csv files. How to solve
> > this problem? Thanks.
> >
> > Discharge
> > 7.58 :2
> > 6.4   :1
> > 6.82 :1
> > 8.63 :1
> > 8.16 :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.
>
>
>
> --
> Gregory (Greg) L. Snow Ph.D.
> 538...@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.


Re: [R] about data problem

2016-09-20 Thread lily li
Is there a function in read.csv that I can use to avoid converting numeric
to factor? Thanks a lot.



On Tue, Sep 20, 2016 at 4:42 PM, lily li <chocol...@gmail.com> wrote:

> Thanks. Then what should I do to solve the problem?
>
> On Tue, Sep 20, 2016 at 4:30 PM, Jeff Newmiller <jdnew...@dcn.davis.ca.us>
> wrote:
>
>> I suppose you can do what works for your data, but I wouldn't recommend
>> na.rm=TRUE because it hides problems rather than clarifying them.
>>
>> If in fact your data includes true NA values (the letters NA or simply
>> nothing between the commas are typical ways this information may be
>> indicated), then read.csv will NOT change from integer to factor
>> (particularly if you have specified which markers represent NA using the
>> na.strings argument documented under read.table)... so you probably DO have
>> unexpected garbage still in your data which could be obscuring valuable
>> information that could affect your conclusions.
>> --
>> Sent from my phone. Please excuse my brevity.
>>
>> On September 20, 2016 3:11:42 PM PDT, lily li <chocol...@gmail.com>
>> wrote:
>> >I reread the data, and use 'na.rm = T' when reading the data. This time
>> >it
>> >has no such problem. It seems that the existence of NAs convert the
>> >integer
>> >to factor. Thanks for your help.
>> >
>> >
>> >On Tue, Sep 20, 2016 at 4:09 PM, Jianling Fan <fanjianl...@gmail.com>
>> >wrote:
>> >
>> >> Add the "stringsAsFactors = F"  when you read the data, and then
>> >> convert them to numeric.
>> >>
>> >> On 20 September 2016 at 16:00, lily li <chocol...@gmail.com> wrote:
>> >> > Yes, it is stored as factor. I can't check out any problem in the
>> >> original
>> >> > data. Reread data doesn't help either. I use read.csv to read in
>> >the
>> >> data,
>> >> > do you think it is better to use read.table? Thanks again.
>> >> >
>> >> > On Tue, Sep 20, 2016 at 3:55 PM, Greg Snow <538...@gmail.com>
>> >wrote:
>> >> >
>> >> >> This indicates that your Discharge column has been
>> >stored/converted as
>> >> >> a factor (run str(df) to verify and check other columns).  This
>> >> >> usually happens when functions like read.table are left to try to
>> >> >> figure out what each column is and it finds something in that
>> >column
>> >> >> that cannot be converted to a number (possibly an oh instead of a
>> >> >> zero, an el instead of a one, or just a letter or punctuation mark
>> >> >> accidentally in the file).  You can either find the error in your
>> >> >> original data, fix it, and reread the data, or specify that the
>> >column
>> >> >> should be numeric using the colClasses argument to read.table or
>> >other
>> >> >> function.
>> >> >>
>> >> >>
>> >> >>
>> >> >> On Tue, Sep 20, 2016 at 3:46 PM, lily li <chocol...@gmail.com>
>> >wrote:
>> >> >> > Hi R users,
>> >> >> >
>> >> >> > I have a problem in reading data.
>> >> >> > For example, part of my dataframe is like this:
>> >> >> >
>> >> >> > df
>> >> >> > month day year  Discharge
>> >> >> >31   20106.4
>> >> >> >32   2010   7.58
>> >> >> >33   2010   6.82
>> >> >> >34   2010   8.63
>> >> >> >35   2010   8.16
>> >> >> >36   2010   7.58
>> >> >> >
>> >> >> > Then if I type summary(df), why it converts the discharge data
>> >to
>> >> >> levels? I
>> >> >> > also met the same problem when reading some other csv files. How
>> >to
>> >> solve
>> >> >> > this problem? Thanks.
>> >> >> >
>> >> >> > Discharge
>> >> >> > 7.58 :2
>> >> >> > 6.4   :1
>> >> >> > 6.82 :1
>> >> >> > 8.63 :1
>> >> >> > 8.16 :1
>> >> >> >
>> >> 

Re: [R] about data problem

2016-09-20 Thread lily li
Yes, I tried to add this statement when reading the dataset.
But when I use summary(df), it shows:
Discharge
Length:
Class  :character
Mode  :character


On Tue, Sep 20, 2016 at 5:06 PM, Joe Ceradini <joecerad...@gmail.com> wrote:

> read.csv("your_data.csv", stringsAsFactors=FALSE)
> (I'm just reiterating Jianling said...)
>
> Joe
>
> On Tue, Sep 20, 2016 at 4:56 PM, lily li <chocol...@gmail.com> wrote:
>
>> Is there a function in read.csv that I can use to avoid converting numeric
>> to factor? Thanks a lot.
>>
>>
>>
>> On Tue, Sep 20, 2016 at 4:42 PM, lily li <chocol...@gmail.com> wrote:
>>
>> > Thanks. Then what should I do to solve the problem?
>> >
>> > On Tue, Sep 20, 2016 at 4:30 PM, Jeff Newmiller <
>> jdnew...@dcn.davis.ca.us>
>> > wrote:
>> >
>> >> I suppose you can do what works for your data, but I wouldn't recommend
>> >> na.rm=TRUE because it hides problems rather than clarifying them.
>> >>
>> >> If in fact your data includes true NA values (the letters NA or simply
>> >> nothing between the commas are typical ways this information may be
>> >> indicated), then read.csv will NOT change from integer to factor
>> >> (particularly if you have specified which markers represent NA using
>> the
>> >> na.strings argument documented under read.table)... so you probably DO
>> have
>> >> unexpected garbage still in your data which could be obscuring valuable
>> >> information that could affect your conclusions.
>> >> --
>> >> Sent from my phone. Please excuse my brevity.
>> >>
>> >> On September 20, 2016 3:11:42 PM PDT, lily li <chocol...@gmail.com>
>> >> wrote:
>> >> >I reread the data, and use 'na.rm = T' when reading the data. This
>> time
>> >> >it
>> >> >has no such problem. It seems that the existence of NAs convert the
>> >> >integer
>> >> >to factor. Thanks for your help.
>> >> >
>> >> >
>> >> >On Tue, Sep 20, 2016 at 4:09 PM, Jianling Fan <fanjianl...@gmail.com>
>> >> >wrote:
>> >> >
>> >> >> Add the "stringsAsFactors = F"  when you read the data, and then
>> >> >> convert them to numeric.
>> >> >>
>> >> >> On 20 September 2016 at 16:00, lily li <chocol...@gmail.com> wrote:
>> >> >> > Yes, it is stored as factor. I can't check out any problem in the
>> >> >> original
>> >> >> > data. Reread data doesn't help either. I use read.csv to read in
>> >> >the
>> >> >> data,
>> >> >> > do you think it is better to use read.table? Thanks again.
>> >> >> >
>> >> >> > On Tue, Sep 20, 2016 at 3:55 PM, Greg Snow <538...@gmail.com>
>> >> >wrote:
>> >> >> >
>> >> >> >> This indicates that your Discharge column has been
>> >> >stored/converted as
>> >> >> >> a factor (run str(df) to verify and check other columns).  This
>> >> >> >> usually happens when functions like read.table are left to try to
>> >> >> >> figure out what each column is and it finds something in that
>> >> >column
>> >> >> >> that cannot be converted to a number (possibly an oh instead of a
>> >> >> >> zero, an el instead of a one, or just a letter or punctuation
>> mark
>> >> >> >> accidentally in the file).  You can either find the error in your
>> >> >> >> original data, fix it, and reread the data, or specify that the
>> >> >column
>> >> >> >> should be numeric using the colClasses argument to read.table or
>> >> >other
>> >> >> >> function.
>> >> >> >>
>> >> >> >>
>> >> >> >>
>> >> >> >> On Tue, Sep 20, 2016 at 3:46 PM, lily li <chocol...@gmail.com>
>> >> >wrote:
>> >> >> >> > Hi R users,
>> >> >> >> >
>> >> >> >> > I have a problem in reading data.
>> >> >> >> > For example, part of my dataframe is like this:
>> >> >> >> >
>> >> >> >> > df
>> >> >> >>

Re: [R] about data problem

2016-09-20 Thread lily li
Thanks. The former method works. I confused character with factor.

Besides, I should use: dta$DischargeNum <- as.numeric( dta$Discharge )
instead of: dta$Discharge <- as.numeric( dta$Discharge )


On Tue, Sep 20, 2016 at 5:18 PM, Jeff Newmiller <jdnew...@dcn.davis.ca.us>
wrote:

> Which means it avoided converting to factor... Success!
>
> Note that the column apparently has garbage characters in one or more of
> the rows, which should be evident when you LOOK AT THE CHARACTERS in the
> column. They should all be numeric symbols, plus or minus, and perhaps
> decimal points. If they are not, then the conversion to numeric will be
> incomplete. See my other message. You have the choice of editing the file
> (may have concerns with traceability), or you can write R code that removes
> the garbage characters using gsub.
> --
> Sent from my phone. Please excuse my brevity.
>
> On September 20, 2016 4:09:02 PM PDT, lily li <chocol...@gmail.com> wrote:
> >Yes, I tried to add this statement when reading the dataset.
> >But when I use summary(df), it shows:
> >Discharge
> >Length:
> >Class  :character
> >Mode  :character
> >
> >
> >On Tue, Sep 20, 2016 at 5:06 PM, Joe Ceradini <joecerad...@gmail.com>
> >wrote:
> >
> >> read.csv("your_data.csv", stringsAsFactors=FALSE)
> >> (I'm just reiterating Jianling said...)
> >>
> >> Joe
> >>
> >> On Tue, Sep 20, 2016 at 4:56 PM, lily li <chocol...@gmail.com> wrote:
> >>
> >>> Is there a function in read.csv that I can use to avoid converting
> >numeric
> >>> to factor? Thanks a lot.
> >>>
> >>>
> >>>
> >>> On Tue, Sep 20, 2016 at 4:42 PM, lily li <chocol...@gmail.com>
> >wrote:
> >>>
> >>> > Thanks. Then what should I do to solve the problem?
> >>> >
> >>> > On Tue, Sep 20, 2016 at 4:30 PM, Jeff Newmiller <
> >>> jdnew...@dcn.davis.ca.us>
> >>> > wrote:
> >>> >
> >>> >> I suppose you can do what works for your data, but I wouldn't
> >recommend
> >>> >> na.rm=TRUE because it hides problems rather than clarifying them.
> >>> >>
> >>> >> If in fact your data includes true NA values (the letters NA or
> >simply
> >>> >> nothing between the commas are typical ways this information may
> >be
> >>> >> indicated), then read.csv will NOT change from integer to factor
> >>> >> (particularly if you have specified which markers represent NA
> >using
> >>> the
> >>> >> na.strings argument documented under read.table)... so you
> >probably DO
> >>> have
> >>> >> unexpected garbage still in your data which could be obscuring
> >valuable
> >>> >> information that could affect your conclusions.
> >>> >> --
> >>> >> Sent from my phone. Please excuse my brevity.
> >>> >>
> >>> >> On September 20, 2016 3:11:42 PM PDT, lily li
> ><chocol...@gmail.com>
> >>> >> wrote:
> >>> >> >I reread the data, and use 'na.rm = T' when reading the data.
> >This
> >>> time
> >>> >> >it
> >>> >> >has no such problem. It seems that the existence of NAs convert
> >the
> >>> >> >integer
> >>> >> >to factor. Thanks for your help.
> >>> >> >
> >>> >> >
> >>> >> >On Tue, Sep 20, 2016 at 4:09 PM, Jianling Fan
> ><fanjianl...@gmail.com>
> >>> >> >wrote:
> >>> >> >
> >>> >> >> Add the "stringsAsFactors = F"  when you read the data, and
> >then
> >>> >> >> convert them to numeric.
> >>> >> >>
> >>> >> >> On 20 September 2016 at 16:00, lily li <chocol...@gmail.com>
> >wrote:
> >>> >> >> > Yes, it is stored as factor. I can't check out any problem
> >in the
> >>> >> >> original
> >>> >> >> > data. Reread data doesn't help either. I use read.csv to
> >read in
> >>> >> >the
> >>> >> >> data,
> >>> >> >> > do you think it is better to use read.table? Thanks again.
> >>> >> >> >
> >>> >> >> > On Tue, Sep 20, 2016 at 3:55

[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.


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 <chocol...@gmail.com> 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] 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] About reshape dataset

2016-10-22 Thread lily li
The code I'm using is:
require(reshape)
DF2 = melt(DF, id.vars = c('year', 'month', 'day'), measure.vars =
c('site1_elev', 'site2_elev', 'site1_temp', 'site2_temp'))

But it didn't work.

On Sat, Oct 22, 2016 at 11:50 AM, lily li <chocol...@gmail.com> wrote:

> Hi R users,
>
> I want to melt a dataframe, but it mixed up the variables.
>
> DF is the original dataset:
> year  month  day  site1_elev  site2_elev  site1_temp  site2_temp
> 2000 561300  150020
>  21
> 2000 571300  150021  22
> 2000 581300  150019  20
> 2000 591300  150022  23
>
> How to melt the dataframe and get the following dataset? Thanks for your
> help.
>
> year  month  day  siteID   elev   temp
> 20005 6   1  130020
> 20005 6   2  150021
> 20005 7   1  130021
> 20005 7   2  150022
>
>

[[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 reshape dataset

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

I want to melt a dataframe, but it mixed up the variables.

DF is the original dataset:
year  month  day  site1_elev  site2_elev  site1_temp  site2_temp
2000 561300  150020  21

2000 571300  150021  22
2000 581300  150019  20
2000 591300  150022  23

How to melt the dataframe and get the following dataset? Thanks for your
help.

year  month  day  siteID   elev   temp
20005 6   1  130020
20005 6   2  150021
20005 7   1  130021
20005 7   2  150022

[[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==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.


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 <jholt...@gmail.com> 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 <chocol...@gmail.com> 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==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-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.


[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 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 <ruipbarra...@sapo.pt> 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 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.


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 <ruipbarra...@sapo.pt> 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.


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 <dulca...@bigpond.com> 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 <ruipbarra...@sapo.pt>
> 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-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 <dwinsem...@comcast.net>
wrote:

>
> > On Dec 31, 2016, at 9:26 AM, lily li <chocol...@gmail.com> 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 <dulca...@bigpond.com>
> 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 <ruipbarra...@sapo.pt>
> >> 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
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 <chocol...@gmail.com> 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 <dwinsem...@comcast.net>
> wrote:
>
>>
>> > On Dec 31, 2016, at 9:26 AM, lily li <chocol...@gmail.com> 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 <dulca...@bigpond.com>
>> 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 <ruipbarra...@sapo.pt>
>> >> 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
>> >>>> a

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 <bgunter.4...@gmail.com>
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 <chocol...@gmail.com> 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 <dulca...@bigpond.com>
> 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 <ruipbarra...@sapo.pt>
> >> 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
&g

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 <r...@temple.edu>
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 <chocol...@gmail.com> 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 <ruipbarra...@sapo.pt>
> 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.


[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 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 <chocol...@gmail.com> 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 <chocol...@gmail.com> 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 <chocol...@gmail.com> 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 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 <bgunter.4...@gmail.com>
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 <chocol...@gmail.com> 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 <chocol...@gmail.com> 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 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 <bgunter.4...@gmail.com>
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 <chocol...@gmail.com> 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 <bgunter.4...@gmail.com>
> > 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 <chocol...@gmail.com> 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 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 <bgunter.4...@gmail.com> 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 <chocol...@gmail.com> 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 <chocol...@gmail.com> 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.

[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 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 <drjimle...@gmail.com> 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 <chocol...@gmail.com> 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.


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 <chocol...@gmail.com> 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 <drjimle...@gmail.com> 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 <chocol...@gmail.com> 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.


[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 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 <drjimle...@gmail.com> 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 <chocol...@gmail.com> 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 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.


[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 installing smwrGraphs package

2017-07-24 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 <pda...@gmail.com> wrote:

>
> > On 23 Jul 2017, at 18:31 , Uwe Ligges <lig...@statistik.tu-dortmund.de>
> 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 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] about reading files in order

2017-06-29 Thread lily li
Thanks also.

On Thu, Jun 29, 2017 at 2:12 PM, Adams, Jean <jvad...@usgs.gov> 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 <chocol...@gmail.com> 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.


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 <ky...@email.vccs.edu> 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" <chocol...@gmail.com> 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 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 <bgunter.4...@gmail.com> 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 <chocol...@gmail.com> 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.


[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.

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 <sezenism...@gmail.com> wrote:

>
> > On 6 Aug 2017, at 03:01, lily li <chocol...@gmail.com> 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.

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 <hdo...@air.org> 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 <r-help@r-project.org>
> 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
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 <cdeterma...@gmail.com>
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 <chocol...@gmail.com> 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 <hdo...@air.org> 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 <hdo...@air.org>
>> > *Cc:* R mailing list <r-help@r-project.org>
>> > *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 <hdo...@air.org> 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 <r-help@r-project.org>
>> > 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,

[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 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 <hdo...@air.org> 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 <hdo...@air.org>
> *Cc:* R mailing list <r-help@r-project.org>
> *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 <hdo...@air.org> 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 <r-help@r-project.org>
> 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
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 <hdo...@air.org> wrote:

> ?round
>
>
>
>
>
> *From:* lily li [mailto:chocol...@gmail.com]
> *Sent:* Tuesday, May 09, 2017 11:10 AM
> *To:* Charles Determan <cdeterma...@gmail.com>
> *Cc:* Doran, Harold <hdo...@air.org>; R mailing list <r-help@r-project.org
> >
> *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 <cdeterma...@gmail.com>
> 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 <chocol...@gmail.com> 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 <hdo...@air.org> 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 <hdo...@air.org>
> > *Cc:* R mailing list <r-help@r-project.org>
> > *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 <hdo...@air.org> 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 <r-help@r-project.org>
>
> > 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
> >

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 <hdo...@air.org> 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 <hdo...@air.org>
> *Cc:* Charles Determan <cdeterma...@gmail.com>; 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 <hdo...@air.org> wrote:
>
> ?round
>
>
>
>
>
> *From:* lily li [mailto:chocol...@gmail.com]
> *Sent:* Tuesday, May 09, 2017 11:10 AM
> *To:* Charles Determan <cdeterma...@gmail.com>
> *Cc:* Doran, Harold <hdo...@air.org>; R mailing list <r-help@r-project.org
> >
> *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 <cdeterma...@gmail.com>
> 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 <chocol...@gmail.com> 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 <hdo...@air.org> 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 <hdo...@air.org>
> > *Cc:* R mailing list <r-help@r-project.org>
> > *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 <hdo...@air.org> 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 <r-help@r-project.org>
>
> > 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
> >
>

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 <drjimle...@gmail.com> 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 <chocol...@gmail.com> 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] 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
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.


[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 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 <calan...@rgzm.de> 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 <chocol...@gmail.com> 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
> >>&

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 <ulrik.ster...@gmail.com>
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 <chocol...@gmail.com> 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.


  1   2   >