HI Elaine,
You only provided an object "datam" and the dput(dta).? I don't
know what is inside "datam".? Your question "how to use the
object "datam" in connection with the code ..." is very
confusing.? Do you want to find if datam is a subset of dta or something else??
Regarding your other question regaring the row.names(NA, -11L), If you change it
manually to row.names(NA,11L), may not make any difference.?? This link might be
useful:
http://stackoverflow.com/questions/7014387/whats-the-difference-between-1l-and-1
?dta1<-structure(list(Species = structure(1:11, .Label = c("Butterfly
A1",
?"Butterfly A2", "Butterfly A3", "Butterfly A4",
"Butterfly B1",
?"Butterfly B2", "Butterfly B3", "Butterfly B4",
"Butterfly B5",
?"Butterfly C1", "Butterfly C2"), class =
"factor"), Range = c(130.5,
?450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
?720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
?16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c("Species",
"Range",
?"Latitude"), class = "data.frame", row.names = c(NA, 11L))
?identical(dta,dta1)
#[1] TRUE
Suppose, you change your row.names:
?dta4<-dta
?row.names(dta4)<-paste0("A",1:11)
?dput(dta4)
structure(list(Species = structure(1:11, .Label = c("Butterfly A1",
"Butterfly A2", "Butterfly A3", "Butterfly A4",
"Butterfly B1",
"Butterfly B2", "Butterfly B3", "Butterfly B4",
"Butterfly B5",
"Butterfly C1", "Butterfly C2"), class =
"factor"), Range = c(130.5,
450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c("Species",
"Range",
"Latitude"), class = "data.frame", row.names =
c("A1", "A2",
"A3", "A4", "A5", "A6", "A7",
"A8", "A9", "A10", "A11"))
I hope it helps.
A.K.
________________________________
From: Elaine Kuo <elaine.kuo.tw at gmail.com>
To: arun <smartpink111 at yahoo.com>
Sent: Monday, December 17, 2012 8:35 AM
Subject: Re: [R] averaging X of specific Y (latitude)
Thanks for the immediate response.
You are right. It is unclear.
Please kindly find the code below written by a R beginner like me.
My question is?
how to use the object "datam" in connection with the code starting
with dta <-?
For example, is it possible to find the text below inside "datam"??
"Butterfly A1","Butterfly A2", "Butterfly A3",?
?"Butterfly A4", "Butterfly B1","Butterfly B2",
"Butterfly B3", "Butterfly B4", "Butterfly B5",
?"Butterfly C1", "Butterfly C2"
Thank you again.
Elaine
code
datam <-read.csv('H:/R_data/bfly.csv',header=T, row.names=1)
dim(datam)
datam[1,]
str(datam)
dput(datam, "datam")
?dta <- structure(list(Species = structure(1:11, .Label = c("Butterfly
A1","Butterfly A2", "Butterfly A3",?
?"Butterfly A4", "Butterfly B1","Butterfly B2",
"Butterfly B3", "Butterfly B4", "Butterfly B5",
?"Butterfly C1", "Butterfly C2"), class =
"factor"), Range = c(130.5,
?450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
?720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
?16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c("Species",
"Range", "Latitude"), class = "data.frame",
row.names = c(NA, -11L))
Bfly <- aggregate(Range~Species+floor(Latitude), dta, mean)
colnames(Bfly) <- c("Species", "Latitude",
"Mean")
Bfly
On Mon, Dec 17, 2012 at 9:23 PM, arun <smartpink111 at yahoo.com> wrote:
HI,>Your question is not very clear.
>
>You get the "structure" like code by dput(datam).
>A.K.
>
>
>
>
>
>
>----- Original Message -----
>From: Elaine Kuo <elaine.kuo.tw at gmail.com>
>To: dcarlson at tamu.edu; r-help at r-project.org
>
>Cc:
>Sent: Monday, December 17, 2012 6:55 AM
>Subject: Re: [R] averaging X of specific Y (latitude)
>
>Another question (I am sure it is the last one tentatively):
>
>After creating a text.file using dput (let's name the created file
>"datam"),
>please kindly advise how to use the text file in writing the code using
>"structure" like below.
>
>Thank you.
>
>code
>dta <- structure(list(Species = structure(1:11, .Label =
c("Butterfly A1",
>
>+ "Butterfly A2", "Butterfly A3", "Butterfly
A4", "Butterfly B1",
>+ "Butterfly B2", "Butterfly B3", "Butterfly
B4", "Butterfly B5",
>+ "Butterfly C1", "Butterfly C2"), class =
"factor"), Range = c(130.5,
>+ 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
>+ 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
>+ 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c("Species",
"Range",
>+ "Latitude"), class = "data.frame", row.names = c(NA,
-11L)))
>
>Elaine
>
>
>On Mon, Dec 17, 2012 at 7:40 PM, Elaine Kuo <elaine.kuo.tw at
gmail.com> wrote:
>
>> One more question:
>>
>> Please kindly explain
>> why it is written as "row.names = c(NA, -11L))."
>> (in the code below)
>>
>> I am unsure why it is "negative" 11.
>> Thank you .
>>
>> Elaine
>>
>> code
>>
>> dta <- structure(list(Species = structure(1:11, .Label =
c("Butterfly A1",
>>
>> + "Butterfly A2", "Butterfly A3", "Butterfly
A4", "Butterfly B1",
>> + "Butterfly B2", "Butterfly B3", "Butterfly
B4", "Butterfly B5",
>> + "Butterfly C1", "Butterfly C2"), class =
"factor"), Range = c(130.5,
>> + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2, 620.11, 982.78,
>> + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4, 10.54, 10.87,
>> + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names = c("Species",
"Range",
>> + "Latitude"), class = "data.frame", row.names =
c(NA, -11L)))
>>
>>
>>
>>>> >>
>>>> >>
>>>> >> ----- Original Message -----
>>>> >> From: David L Carlson <dcarlson at tamu.edu>
>>>> >> To: 'Elaine Kuo' <elaine.kuo.tw at
gmail.com>; r-help at r-project.org;
>>>> >> 'r-sig-geo' <r-sig-geo at
stat.math.ethz.ch>
>>>> >> Cc:
>>>> >> Sent: Sunday, December 16, 2012 11:32 AM
>>>> >> Subject: Re: [R] averaging X of specific Y (latitude)
>>>> >>
>>>> >> It is better to use dput() in R to create a text
version of your data
>>>> for
>>>> >> us
>>>> >> to work with. The aggregate command below gives you
the mean ranges by
>>>> >> butterfly species and latititude and saves the result
as Bfly. The
>>>> >> colnames() command simply renames the columns:
>>>> >>
>>>> >>> dta <- structure(list(Species = structure(1:11,
.Label = c("Butterfly
>>>> >> A1",
>>>> >>
>>>> >> + "Butterfly A2", "Butterfly A3",
"Butterfly A4", "Butterfly B1",
>>>> >> + "Butterfly B2", "Butterfly B3",
"Butterfly B4", "Butterfly B5",
>>>> >> + "Butterfly C1", "Butterfly C2"),
class = "factor"), Range = c(130.5,
>>>> >> + 450.68, 1102.38, 893.34, 820.2, 872.2, 488.2,
620.11, 982.78,
>>>> >> + 720.32, 912.2), Latitude = c(9.45, 10.2, 9.3, 16.4,
10.54, 10.87,
>>>> >> + 16.79, 18.3, 12.98, 12.67, 18.07)), .Names =
c("Species", "Range",
>>>> >> + "Latitude"), class =
"data.frame", row.names = c(NA, -11L))
>>>> >>> Bfly <-
aggregate(Range~Species+floor(Latitude), dta, mean)
>>>> >>> colnames(Bfly) <- c("Species",
"Latitude", "Mean")
>>>> >>> Bfly
>>>> >>? ? ? ? Species Latitude? ? Mean
>>>> >> 1? Butterfly A1? ? ? ? 9? 130.50
>>>> >> 2? Butterfly A3? ? ? ? 9 1102.38
>>>> >> 3? Butterfly A2? ? ? ?10? 450.68
>>>> >> 4? Butterfly B1? ? ? ?10? 820.20
>>>> >> 5? Butterfly B2? ? ? ?10? 872.20
>>>> >> 6? Butterfly B5? ? ? ?12? 982.78
>>>> >> 7? Butterfly C1? ? ? ?12? 720.32
>>>> >> 8? Butterfly A4? ? ? ?16? 893.34
>>>> >> 9? Butterfly B3? ? ? ?16? 488.20
>>>> >> 10 Butterfly B4? ? ? ?18? 620.11
>>>> >> 11 Butterfly C2? ? ? ?18? 912.20
>>>> >>
>>>> >> ----------------------------------------------
>>>> >> David L Carlson
>>>> >> Associate Professor of Anthropology
>>>> >> Texas A&M University
>>>> >> College Station, TX 77843-4352
>>>> >>
>>>> >>> -----Original Message-----
>>>> >>> From: r-help-bounces at r-project.org
[mailto:r-help-bounces at r-
>>>> >>> project.org] On Behalf Of Elaine Kuo
>>>> >>> Sent: Saturday, December 15, 2012 10:15 PM
>>>> >>> To: r-help at r-project.org; r-sig-geo
>>>> >>> Subject: [R] averaging X of specific Y (latitude)
>>>> >>>
>>>> >>> Hello
>>>> >>>
>>>> >>>
>>>> >>>
>>>> >>> I have a table describing butterfly range traits.
>>>> >>>
>>>> >>> It is composed of three columns as below
>>>> >>>
>>>> >>>
>>>> >>>
>>>> >>> Species name? range size (X)? ? latitude of range
midpoint (Y)
>>>> >>>
>>>> >>>
>>>> >>>
>>>> >>> There are 11 kinds of butterflies.
>>>> >>>
>>>> >>> Each has its range size, and the latitude of each
range midpoint
>>>> ranges
>>>> >>> from 9 to 19.
>>>> >>>
>>>> >>> I would like to have the average range size of
every degree of
>>>> >>> latitude.
>>>> >>>
>>>> >>> For example, the average range size of latitude
degree 10
>>>> (10.0-10.99:
>>>> >>> Butterfly A2, B1, B2)
>>>> >>>
>>>> >>> Please kindly help with R code to calculate the
average values.
>>>> >>>
>>>> >>> Thank you.
>>>> >>>
>>>> >>>
>>>> >>> Elaine
>>>> >>>
>>>> >>>
>>>> >>> The details are as followed.
>>>> >>>
>>>> >>>
>>>> >>>
>>>> >>> Butterfly A1? ? ? 130.5? ? ? ? ? ? ? ? ?9.45
>>>> >>>
>>>> >>> Butterfly A2? ? ? 450.68? ? ? ? ? ? ? ? ? ? ? ? ?
?10.2
>>>> >>>
>>>> >>> Butterfly A3? ? ? 1102.38? ? ? ? ? ? ? ? ? ? ? ?
9.3
>>>> >>>
>>>> >>> Butterfly A4? ? ? ? ? ? 893.34? ? ? ? ? ? ? ? ? ?
? ? ? ? ?16.4
>>>> >>>
>>>> >>> Butterfly B1? ? ? ? ? ?820.2? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ?10.54
>>>> >>>
>>>> >>> Butterfly B2? ? ? ? ? ? 872.2? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ?10.87
>>>> >>>
>>>> >>> Butterfly B3? ? ? ? ? ? 488.2? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ?16.79
>>>> >>>
>>>> >>> Butterfly B4? ? ? ? ? ? 620.11? ? ? ? ? ? ? ? ? ?
? ? ? ? ?18.3
>>>> >>>
>>>> >>> Butterfly B5? ? ? ? ? ? 982.78? ? ? ? ? ? ? ? ? ?
? ? ? ? ?12.98
>>>> >>>
>>>> >>> Butterfly C1? ? ? ? ? ?720.32? ? ? ? ? ? ? ? ? ? ?
? ? ? ?12.67
>>>> >>>
>>>> >>> Butterfly C2? ? ? ? ? ? 912.2? ? ? ? ? ? ? ? ? ? ?
? ? ? ? ?18.07
>>>> >>>
>>>> >>>? ? [[alternative HTML version deleted]]
>>>> >>>
>>>> >>> ______________________________________________
>>>> >>> R-help at r-project.org mailing list
>>>> >>> 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 at r-project.org mailing list
>>>> >> 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 at r-project.org mailing list
>>>> > 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 at r-project.org mailing list
>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.
>
>