Re: [R] Two conditions selection
Sorry. In dplyr: data %>% filter(col == "blue", cycle ==1) %>% select(values) On Tue, Aug 4, 2015 at 19:54 James Hedges wrote: > cycle %>% filter(col == "blue", cycle == 1) > On Tue, Aug 4, 2015 at 18:59 Rodrigo Díaz wrote: > >> Hi. I have a matrix like this: >> >> cycle=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3))col=c(rep("blue",2),rep("green",2),rep("blue",2),rep("green",2),rep("blue",2),rep("green",2))values=c(1:12)data.frame(cycle,col,values) >> # cycle col values#1 1 blue 1#2 1 blue 2#3 >> 1 green 3#4 2 green 4#5 2 blue 5#6 2 blue >> 6#7 3 green 7#8 3 green 8#9 3 blue 9#10 >>4 blue 10#11 4 green 11#12 4 green 12 >> I want to select or extract values matching 2 conditions. For example: >> values from col "blue" and cycle "1". If I use : values[col==blue] I get >> all blue values. I tried using values[c(col==blue,cycle==1)] but is not >> working. Please help. I have a very big data matrix and I do not wanna go >> to excel and start cutting the 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. >> > [[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] Two conditions selection
cycle %>% filter(col == "blue", cycle == 1) On Tue, Aug 4, 2015 at 18:59 Rodrigo Díaz wrote: > Hi. I have a matrix like this: > > cycle=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3))col=c(rep("blue",2),rep("green",2),rep("blue",2),rep("green",2),rep("blue",2),rep("green",2))values=c(1:12)data.frame(cycle,col,values) > # cycle col values#1 1 blue 1#2 1 blue 2#3 1 > green 3#4 2 green 4#5 2 blue 5#6 2 blue > 6#7 3 green 7#8 3 green 8#9 3 blue 9#10 > 4 blue 10#11 4 green 11#12 4 green 12 > I want to select or extract values matching 2 conditions. For example: > values from col "blue" and cycle "1". If I use : values[col==blue] I get > all blue values. I tried using values[c(col==blue,cycle==1)] but is not > working. Please help. I have a very big data matrix and I do not wanna go > to excel and start cutting the 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. > [[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] Two conditions selection
Rodrigo Díaz wrote > Hi. I have a matrix like this: > cycle=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3))col=c(rep("blue",2),rep("green",2),rep("blue",2),rep("green",2),rep("blue",2),rep("green",2))values=c(1:12)data.frame(cycle,col,values) > # cycle col values#1 1 blue 1#2 1 blue 2#3 1 > green 3#4 2 green 4#5 2 blue 5#6 2 blue > 6#7 3 green 7#8 3 green 8#9 3 blue 9#10 > 4 blue 10#11 4 green 11#12 4 green 12 > I want to select or extract values matching 2 conditions. For example: > values from col "blue" and cycle "1". If I use : values[col==blue] I get > all blue values. I tried using values[c(col==blue,cycle==1)] but is not > working. Please help. I have a very big data matrix and I do not wanna go > to excel and start cutting the data. Thanks. > > > [[alternative HTML version deleted]] > > __ > R-help@ > mailing list -- To UNSUBSCRIBE and 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. How about # Your Code cycle=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3)) col=c(rep("blue",2),rep("green",2),rep("blue",2),rep("green",2),rep("blue",2),rep("green",2)) values=c(1:12) df <- data.frame(cycle,col,values) # Subset data frame df df[cycle==1 & col=="blue",] HTH Pete -- View this message in context: http://r.789695.n4.nabble.com/Two-conditions-selection-tp4710762p4710763.html Sent from the R help mailing list archive at Nabble.com. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Two conditions selection
You need to read up on indexing in R. What you want is logical indexing. You can use just the vectors you created (since you didn't save the data frame that you created) like this > cycle=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3)) > col=c(rep("blue",2),rep("green",2),rep("blue",2),rep("green",2),rep("blue",2),rep("green",2)) > values=c(1:12) > values[col==blue & cycle==1] Or save the data frame and return the rows that you want like this > df <- data.frame(cycle,col,values) > df[df$col==blue & df$cycle==1, ] Hope this is helpful, Dan Daniel Nordlund, PhD Research and Data Analysis Division Services & Enterprise Support Administration Washington State Department of Social and Health Services -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Rodrigo Díaz Sent: Tuesday, August 04, 2015 1:50 PM To: r-help@r-project.org Subject: [R] Two conditions selection Hi. I have a matrix like this: cycle=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3))col=c(rep("blue",2),rep("green",2),rep("blue",2),rep("green",2),rep("blue",2),rep("green",2))values=c(1:12)data.frame(cycle,col,values) # cycle col values#1 1 blue 1#2 1 blue 2#3 1 green 3#4 2 green 4#5 2 blue 5#6 2 blue 6#7 3 green 7#8 3 green 8#9 3 blue 9#10 4 blue 10#11 4 green 11#12 4 green 12 I want to select or extract values matching 2 conditions. For example: values from col "blue" and cycle "1". If I use : values[col==blue] I get all blue values. I tried using values[c(col==blue,cycle==1)] but is not working. Please help. I have a very big data matrix and I do not wanna go to excel and start cutting the data. Thanks. [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] Two conditions selection
Hi. I have a matrix like this: cycle=c(rep(1,3),rep(2,3),rep(3,3),rep(4,3))col=c(rep("blue",2),rep("green",2),rep("blue",2),rep("green",2),rep("blue",2),rep("green",2))values=c(1:12)data.frame(cycle,col,values) # cycle col values#1 1 blue 1#2 1 blue 2#3 1 green 3#4 2 green 4#5 2 blue 5#6 2 blue 6#7 3 green 7#8 3 green 8#9 3 blue 9#10 4 blue 10#11 4 green 11#12 4 green 12 I want to select or extract values matching 2 conditions. For example: values from col "blue" and cycle "1". If I use : values[col==blue] I get all blue values. I tried using values[c(col==blue,cycle==1)] but is not working. Please help. I have a very big data matrix and I do not wanna go to excel and start cutting the 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] Households per Census block
P.S. The US census has different "populations" (or worlds) so make sure the housing variable you use is accessing the correct "world." Best, -- Zack - Zack W. Almquist Assistant Professor Department of Sociology and School of Statistics Affiliate, Minnesota Population Center University of Minnesota On Tue, Aug 4, 2015 at 2:12 PM, Zack Almquist wrote: > Hi Keith, > > > On Tue, Aug 4, 2015 at 12:43 PM, Keith S Weintraub > wrote: > >> I had to download a bunch of stuff but I got it mostly working. >> >> Unfortunately using the alternative method I get the following: >> >> > housing<-CensusAPI2010(c("H0010001"), state.fips=state.fips, level = >> c("block"), key, summaryfile = c("sf1")) >> Error in file(con, "r") : cannot open the connection >> In addition: Warning message: >> In file(con, "r") : cannot open: HTTP status was '400 Bad Request’ >> > > Sorry that is my bad, I didn't verify the variable name at ( > http://api.census.gov/data/2010/sf1/variables.html). This seems to work > for me, as a quick test: > > housing<-CensusAPI2010(variables="H0060001", state.fips="06", level = > c("tract"), key, summaryfile = c("sf1")) > > So the larger example: > > ## Get all states fips code > data(countyfips) > state.fips<-unique(substr(countyfips$fips,1,2)) > head(state.fips) > length(state.fips) ## will be 51=50 (states)+ 1(DC) > ## You will need a census key > key<-"YOUR KEY HERE" > housing<-CensusAPI2010(c("H0060001"), state.fips=state.fips, level = > c("block"), key, summaryfile = c("sf1")) > > should work just fine. > > Best, > > -- Zack > - > Zack W. Almquist > Assistant Professor > Department of Sociology and School of Statistics > Affiliate, Minnesota Population Center > University of Minnesota > > >> I have a feeling that this is not a problem with the API. >> >> Thanks for your help, >> KW >> >> >> >> >> >> >> >> > On Aug 3, 2015, at 2:12 PM, Zack Almquist wrote: >> > >> > Hi Anthony and Keith Weintraub, >> > >> > Here is a way to do what you are asking using the UScensus2010 packages: >> > >> > ## latest version of the package, not yet on CRAN >> > install.packages("UScensus2010", repos="http://R-Forge.R-project.org";) >> > library(UScensus2010) >> > install.blk() >> > library(UScensus2010blk) >> > ### You will want the H0010001 variable (see help(alabama.blk10)) >> > ### Other variables are also available >> > ### You can use the new api function in UScensus2010 to get arbitrary >> variables from SF1 and acs >> > >> > data(states.names) >> > head(states.names) >> > state.blk.housing<-vector("list",length(states.names)) >> > ## notice this could be greatly spead up using the library(parallel) >> > ## with mclapply >> > ## This will be somewhat slow b/c of so much spatial data >> > for(i in 1:length(states.names)){ >> > data(list=paste(states.names[i],"blk10",sep=".")) >> > temp<-get(paste(states.names[i],"blk10",sep=".")) >> >#unique b/c more shapefiles than fips >> > state.blk.housing[[i]]<-unique(temp@data[,c("fips","H0010001")]) >> > print(i) >> > rm(paste(states.names,"blk10",sep=".")) >> > } >> > >> > ### >> > # alternatively Using the US Census API function in the new >> UScensus2010 package >> > ### >> > >> > ## Get all states fips code >> > data(countyfips) >> > state.fips<-unique(substr(countyfips$fips,1,2)) >> > head(state.fips) >> > length(state.fips) ## will be 51=50 (states)+ 1(DC) >> > ## You will need a census key >> > key<-"YOUR KEY HERE" >> > housing<-CensusAPI2010(c("H0010001"), state.fips=state.fips, level = >> c("block"), key, summaryfile = c("sf1")) >> > >> > Best, >> > >> > -- Zack >> > - >> > Zack W. Almquist >> > Assistant Professor >> > Department of Sociology and School of Statistics >> > Affiliate, Minnesota Population Center >> > University of Minnesota >> > >> > >> > On Mon, Aug 3, 2015 at 12:43 PM, Anthony Damico >> wrote: >> > hi, ccing the package maintainer. one alternative is to pull the HU100 >> variable directly from the census bureau's summary files: that variable >> starts at position 328 and ends at 336. just modify this loop and you'll >> get a table with one-record-per-census-block in every state. >> > >> > >> https://github.com/davidbrae/swmap/blob/master/how%20to%20map%20the%20consumer%20expenditure%20survey.R#L104 >> > >> > (1) line 134 change the very last -9 to 9 >> > (2) line 137 between "pop100" and "intptlat" add an "hu100" >> > >> > >> > summary file docs- >> > >> > http://www.census.gov/prod/cen2010/doc/sf1.pdf#page=18 >> > >> > >> > >> > On Mon, Aug 3, 2015 at 11:55 AM, Keith S Weintraub >> wrote: >> > Folks, >> > >> > I am using the UScensus2010 package and I am trying to figure out the >> number of households per census block. >> > >> > There are a number of possible data downloads in the package but >> apparently I am not
Re: [R] Households per Census block
On Aug 4, 2015, at 12:31 PM, Keith S Weintraub wrote: > Can you give me a for-instance of “populations”? Is there a table or chart or > list or… > > Also I guess that I should leave my R session on for as long as possible as > “install.blk” takes a really long time to re-upload if that is what it is > doing. > > Does install.blk go to the source every time? I have no experience with that package, but the help page says: ==: Warning: This is an extremely large file (around 2 gigs) and should only be installed if you have a very good connection. Also it is worth noting that for all systems the install is from source and can take quite a bit of time to install. ==: It also says you need to provide an argument to the function: one of "osx", "linux" or "windows". I would have guessed that you only need to run it once, and after reading its source continue to think that there should have been a package installed, which would then persist and not need to be repeatedly installed. -- David > > Thanks again. > --- > KW > > > > > > > >> On Aug 4, 2015, at 3:22 PM, Zack Almquist wrote: >> >> P.S. The US census has different "populations" (or worlds) so make sure the >> housing variable you use is accessing the correct "world." >> >> Best, >> >> -- Zack >> - >> Zack W. Almquist >> Assistant Professor >> Department of Sociology and School of Statistics >> Affiliate, Minnesota Population Center >> University of Minnesota >> >> On Tue, Aug 4, 2015 at 2:12 PM, Zack Almquist wrote: >> Hi Keith, >> >> >> On Tue, Aug 4, 2015 at 12:43 PM, Keith S Weintraub wrote: >> I had to download a bunch of stuff but I got it mostly working. >> >> Unfortunately using the alternative method I get the following: >> >>> housing<-CensusAPI2010(c("H0010001"), state.fips=state.fips, level = >>> c("block"), key, summaryfile = c("sf1")) >> Error in file(con, "r") : cannot open the connection >> In addition: Warning message: >> In file(con, "r") : cannot open: HTTP status was '400 Bad Request’ >> >> Sorry that is my bad, I didn't verify the variable name at >> (http://api.census.gov/data/2010/sf1/variables.html). This seems to work for >> me, as a quick test: >> >> housing<-CensusAPI2010(variables="H0060001", state.fips="06", level = >> c("tract"), key, summaryfile = c("sf1")) >> >> So the larger example: >> >> ## Get all states fips code >> data(countyfips) >> state.fips<-unique(substr(countyfips$fips,1,2)) >> head(state.fips) >> length(state.fips) ## will be 51=50 (states)+ 1(DC) >> ## You will need a census key >> key<-"YOUR KEY HERE" >> housing<-CensusAPI2010(c("H0060001"), state.fips=state.fips, level = >> c("block"), key, summaryfile = c("sf1")) >> >> should work just fine. >> >> Best, >> >> -- Zack >> - >> Zack W. Almquist >> Assistant Professor >> Department of Sociology and School of Statistics >> Affiliate, Minnesota Population Center >> University of Minnesota >> >> I have a feeling that this is not a problem with the API. >> >> Thanks for your help, >> KW >> >> >> >> >> >> >> >>> On Aug 3, 2015, at 2:12 PM, Zack Almquist wrote: >>> >>> Hi Anthony and Keith Weintraub, >>> >>> Here is a way to do what you are asking using the UScensus2010 packages: >>> >>> ## latest version of the package, not yet on CRAN >>> install.packages("UScensus2010", repos="http://R-Forge.R-project.org";) >>> library(UScensus2010) >>> install.blk() >>> library(UScensus2010blk) >>> ### You will want the H0010001 variable (see help(alabama.blk10)) >>> ### Other variables are also available >>> ### You can use the new api function in UScensus2010 to get arbitrary >>> variables from SF1 and acs >>> >>> data(states.names) >>> head(states.names) >>> state.blk.housing<-vector("list",length(states.names)) >>> ## notice this could be greatly spead up using the library(parallel) >>> ## with mclapply >>> ## This will be somewhat slow b/c of so much spatial data >>> for(i in 1:length(states.names)){ >>> data(list=paste(states.names[i],"blk10",sep=".")) >>> temp<-get(paste(states.names[i],"blk10",sep=".")) >>> #unique b/c more shapefiles than fips >>> state.blk.housing[[i]]<-unique(temp@data[,c("fips","H0010001")]) >>> print(i) >>> rm(paste(states.names,"blk10",sep=".")) >>> } >>> >>> ### >>> # alternatively Using the US Census API function in the new UScensus2010 >>> package >>> ### >>> >>> ## Get all states fips code >>> data(countyfips) >>> state.fips<-unique(substr(countyfips$fips,1,2)) >>> head(state.fips) >>> length(state.fips) ## will be 51=50 (states)+ 1(DC) >>> ## You will need a census key >>> key<-"YOUR KEY HERE" >>> housing<-CensusAPI2010(c("H0010001"), state.fips=state.fips, level = >>> c("block"), key, summaryfile = c("sf1")) >>> >>> Best, >>> >>> -- Zack >>> - >>> Zack W
Re: [R] Households per Census block
Hi Keith, I would only use install.blk() once. Then just load the library(UScensus2010blk) like normal on your machine (this should be relatively fast), redownloading and re-installing each time will be very expensive (both on download and time). The SF1 file manual produced by the US Census goes over all the details of the various variables (http://www.census.gov/prod/cen2010/doc/sf1.pdf) in glorious detail; however a lot of the issues arise depending on if you are interested in individual counts versus household counts and assumptions thereof. Best, -- Zack - Zack W. Almquist Assistant Professor Department of Sociology and School of Statistics Affiliate, Minnesota Population Center University of Minnesota On Tue, Aug 4, 2015 at 2:31 PM, Keith S Weintraub wrote: > Can you give me a for-instance of “populations”? Is there a table or chart > or list or… > > Also I guess that I should leave my R session on for as long as possible > as “install.blk” takes a really long time to re-upload if that is what it > is doing. > > Does install.blk go to the source every time? > > Thanks again. > --- > KW > > > > > > > > > On Aug 4, 2015, at 3:22 PM, Zack Almquist wrote: > > > > P.S. The US census has different "populations" (or worlds) so make sure > the housing variable you use is accessing the correct "world." > > > > Best, > > > > -- Zack > > - > > Zack W. Almquist > > Assistant Professor > > Department of Sociology and School of Statistics > > Affiliate, Minnesota Population Center > > University of Minnesota > > > > On Tue, Aug 4, 2015 at 2:12 PM, Zack Almquist wrote: > > Hi Keith, > > > > > > On Tue, Aug 4, 2015 at 12:43 PM, Keith S Weintraub > wrote: > > I had to download a bunch of stuff but I got it mostly working. > > > > Unfortunately using the alternative method I get the following: > > > > > housing<-CensusAPI2010(c("H0010001"), state.fips=state.fips, level = > c("block"), key, summaryfile = c("sf1")) > > Error in file(con, "r") : cannot open the connection > > In addition: Warning message: > > In file(con, "r") : cannot open: HTTP status was '400 Bad Request’ > > > > Sorry that is my bad, I didn't verify the variable name at ( > http://api.census.gov/data/2010/sf1/variables.html). This seems to work > for me, as a quick test: > > > > housing<-CensusAPI2010(variables="H0060001", state.fips="06", level = > c("tract"), key, summaryfile = c("sf1")) > > > > So the larger example: > > > > ## Get all states fips code > > data(countyfips) > > state.fips<-unique(substr(countyfips$fips,1,2)) > > head(state.fips) > > length(state.fips) ## will be 51=50 (states)+ 1(DC) > > ## You will need a census key > > key<-"YOUR KEY HERE" > > housing<-CensusAPI2010(c("H0060001"), state.fips=state.fips, level = > c("block"), key, summaryfile = c("sf1")) > > > > should work just fine. > > > > Best, > > > > -- Zack > > - > > Zack W. Almquist > > Assistant Professor > > Department of Sociology and School of Statistics > > Affiliate, Minnesota Population Center > > University of Minnesota > > > > I have a feeling that this is not a problem with the API. > > > > Thanks for your help, > > KW > > > > > > > > > > > > > > > > > On Aug 3, 2015, at 2:12 PM, Zack Almquist wrote: > > > > > > Hi Anthony and Keith Weintraub, > > > > > > Here is a way to do what you are asking using the UScensus2010 > packages: > > > > > > ## latest version of the package, not yet on CRAN > > > install.packages("UScensus2010", repos="http://R-Forge.R-project.org";) > > > library(UScensus2010) > > > install.blk() > > > library(UScensus2010blk) > > > ### You will want the H0010001 variable (see help(alabama.blk10)) > > > ### Other variables are also available > > > ### You can use the new api function in UScensus2010 to get arbitrary > variables from SF1 and acs > > > > > > data(states.names) > > > head(states.names) > > > state.blk.housing<-vector("list",length(states.names)) > > > ## notice this could be greatly spead up using the library(parallel) > > > ## with mclapply > > > ## This will be somewhat slow b/c of so much spatial data > > > for(i in 1:length(states.names)){ > > > data(list=paste(states.names[i],"blk10",sep=".")) > > > temp<-get(paste(states.names[i],"blk10",sep=".")) > > >#unique b/c more shapefiles than fips > > > state.blk.housing[[i]]<-unique(temp@data[,c("fips","H0010001")]) > > > print(i) > > > rm(paste(states.names,"blk10",sep=".")) > > > } > > > > > > ### > > > # alternatively Using the US Census API function in the new > UScensus2010 package > > > ### > > > > > > ## Get all states fips code > > > data(countyfips) > > > state.fips<-unique(substr(countyfips$fips,1,2)) > > > head(state.fips) > > > length(state.fips) ## will be 51=50 (states)+ 1(DC) > > > ## You will need a census key > > > key<-"YOUR KEY HERE
Re: [R] Households per Census block
Hi Keith, On Tue, Aug 4, 2015 at 12:43 PM, Keith S Weintraub wrote: > I had to download a bunch of stuff but I got it mostly working. > > Unfortunately using the alternative method I get the following: > > > housing<-CensusAPI2010(c("H0010001"), state.fips=state.fips, level = > c("block"), key, summaryfile = c("sf1")) > Error in file(con, "r") : cannot open the connection > In addition: Warning message: > In file(con, "r") : cannot open: HTTP status was '400 Bad Request’ > Sorry that is my bad, I didn't verify the variable name at ( http://api.census.gov/data/2010/sf1/variables.html). This seems to work for me, as a quick test: housing<-CensusAPI2010(variables="H0060001", state.fips="06", level = c("tract"), key, summaryfile = c("sf1")) So the larger example: ## Get all states fips code data(countyfips) state.fips<-unique(substr(countyfips$fips,1,2)) head(state.fips) length(state.fips) ## will be 51=50 (states)+ 1(DC) ## You will need a census key key<-"YOUR KEY HERE" housing<-CensusAPI2010(c("H0060001"), state.fips=state.fips, level = c("block"), key, summaryfile = c("sf1")) should work just fine. Best, -- Zack - Zack W. Almquist Assistant Professor Department of Sociology and School of Statistics Affiliate, Minnesota Population Center University of Minnesota > I have a feeling that this is not a problem with the API. > > Thanks for your help, > KW > > > > > > > > > On Aug 3, 2015, at 2:12 PM, Zack Almquist wrote: > > > > Hi Anthony and Keith Weintraub, > > > > Here is a way to do what you are asking using the UScensus2010 packages: > > > > ## latest version of the package, not yet on CRAN > > install.packages("UScensus2010", repos="http://R-Forge.R-project.org";) > > library(UScensus2010) > > install.blk() > > library(UScensus2010blk) > > ### You will want the H0010001 variable (see help(alabama.blk10)) > > ### Other variables are also available > > ### You can use the new api function in UScensus2010 to get arbitrary > variables from SF1 and acs > > > > data(states.names) > > head(states.names) > > state.blk.housing<-vector("list",length(states.names)) > > ## notice this could be greatly spead up using the library(parallel) > > ## with mclapply > > ## This will be somewhat slow b/c of so much spatial data > > for(i in 1:length(states.names)){ > > data(list=paste(states.names[i],"blk10",sep=".")) > > temp<-get(paste(states.names[i],"blk10",sep=".")) > >#unique b/c more shapefiles than fips > > state.blk.housing[[i]]<-unique(temp@data[,c("fips","H0010001")]) > > print(i) > > rm(paste(states.names,"blk10",sep=".")) > > } > > > > ### > > # alternatively Using the US Census API function in the new UScensus2010 > package > > ### > > > > ## Get all states fips code > > data(countyfips) > > state.fips<-unique(substr(countyfips$fips,1,2)) > > head(state.fips) > > length(state.fips) ## will be 51=50 (states)+ 1(DC) > > ## You will need a census key > > key<-"YOUR KEY HERE" > > housing<-CensusAPI2010(c("H0010001"), state.fips=state.fips, level = > c("block"), key, summaryfile = c("sf1")) > > > > Best, > > > > -- Zack > > - > > Zack W. Almquist > > Assistant Professor > > Department of Sociology and School of Statistics > > Affiliate, Minnesota Population Center > > University of Minnesota > > > > > > On Mon, Aug 3, 2015 at 12:43 PM, Anthony Damico > wrote: > > hi, ccing the package maintainer. one alternative is to pull the HU100 > variable directly from the census bureau's summary files: that variable > starts at position 328 and ends at 336. just modify this loop and you'll > get a table with one-record-per-census-block in every state. > > > > > https://github.com/davidbrae/swmap/blob/master/how%20to%20map%20the%20consumer%20expenditure%20survey.R#L104 > > > > (1) line 134 change the very last -9 to 9 > > (2) line 137 between "pop100" and "intptlat" add an "hu100" > > > > > > summary file docs- > > > > http://www.census.gov/prod/cen2010/doc/sf1.pdf#page=18 > > > > > > > > On Mon, Aug 3, 2015 at 11:55 AM, Keith S Weintraub > wrote: > > Folks, > > > > I am using the UScensus2010 package and I am trying to figure out the > number of households per census block. > > > > There are a number of possible data downloads in the package but > apparently I am not smart enough to figure out which data-set is > appropriate and what functions to use. > > > > Any help or pointers or links would be greatly appreciated. > > > > Thanks for your time, > > Best, > > KW > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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]]
Re: [R] Households per Census block
Can you give me a for-instance of “populations”? Is there a table or chart or list or… Also I guess that I should leave my R session on for as long as possible as “install.blk” takes a really long time to re-upload if that is what it is doing. Does install.blk go to the source every time? Thanks again. --- KW > On Aug 4, 2015, at 3:22 PM, Zack Almquist wrote: > > P.S. The US census has different "populations" (or worlds) so make sure the > housing variable you use is accessing the correct "world." > > Best, > > -- Zack > - > Zack W. Almquist > Assistant Professor > Department of Sociology and School of Statistics > Affiliate, Minnesota Population Center > University of Minnesota > > On Tue, Aug 4, 2015 at 2:12 PM, Zack Almquist wrote: > Hi Keith, > > > On Tue, Aug 4, 2015 at 12:43 PM, Keith S Weintraub wrote: > I had to download a bunch of stuff but I got it mostly working. > > Unfortunately using the alternative method I get the following: > > > housing<-CensusAPI2010(c("H0010001"), state.fips=state.fips, level = > > c("block"), key, summaryfile = c("sf1")) > Error in file(con, "r") : cannot open the connection > In addition: Warning message: > In file(con, "r") : cannot open: HTTP status was '400 Bad Request’ > > Sorry that is my bad, I didn't verify the variable name at > (http://api.census.gov/data/2010/sf1/variables.html). This seems to work for > me, as a quick test: > > housing<-CensusAPI2010(variables="H0060001", state.fips="06", level = > c("tract"), key, summaryfile = c("sf1")) > > So the larger example: > > ## Get all states fips code > data(countyfips) > state.fips<-unique(substr(countyfips$fips,1,2)) > head(state.fips) > length(state.fips) ## will be 51=50 (states)+ 1(DC) > ## You will need a census key > key<-"YOUR KEY HERE" > housing<-CensusAPI2010(c("H0060001"), state.fips=state.fips, level = > c("block"), key, summaryfile = c("sf1")) > > should work just fine. > > Best, > > -- Zack > - > Zack W. Almquist > Assistant Professor > Department of Sociology and School of Statistics > Affiliate, Minnesota Population Center > University of Minnesota > > I have a feeling that this is not a problem with the API. > > Thanks for your help, > KW > > > > > > > > > On Aug 3, 2015, at 2:12 PM, Zack Almquist wrote: > > > > Hi Anthony and Keith Weintraub, > > > > Here is a way to do what you are asking using the UScensus2010 packages: > > > > ## latest version of the package, not yet on CRAN > > install.packages("UScensus2010", repos="http://R-Forge.R-project.org";) > > library(UScensus2010) > > install.blk() > > library(UScensus2010blk) > > ### You will want the H0010001 variable (see help(alabama.blk10)) > > ### Other variables are also available > > ### You can use the new api function in UScensus2010 to get arbitrary > > variables from SF1 and acs > > > > data(states.names) > > head(states.names) > > state.blk.housing<-vector("list",length(states.names)) > > ## notice this could be greatly spead up using the library(parallel) > > ## with mclapply > > ## This will be somewhat slow b/c of so much spatial data > > for(i in 1:length(states.names)){ > > data(list=paste(states.names[i],"blk10",sep=".")) > > temp<-get(paste(states.names[i],"blk10",sep=".")) > >#unique b/c more shapefiles than fips > > state.blk.housing[[i]]<-unique(temp@data[,c("fips","H0010001")]) > > print(i) > > rm(paste(states.names,"blk10",sep=".")) > > } > > > > ### > > # alternatively Using the US Census API function in the new UScensus2010 > > package > > ### > > > > ## Get all states fips code > > data(countyfips) > > state.fips<-unique(substr(countyfips$fips,1,2)) > > head(state.fips) > > length(state.fips) ## will be 51=50 (states)+ 1(DC) > > ## You will need a census key > > key<-"YOUR KEY HERE" > > housing<-CensusAPI2010(c("H0010001"), state.fips=state.fips, level = > > c("block"), key, summaryfile = c("sf1")) > > > > Best, > > > > -- Zack > > - > > Zack W. Almquist > > Assistant Professor > > Department of Sociology and School of Statistics > > Affiliate, Minnesota Population Center > > University of Minnesota > > > > > > On Mon, Aug 3, 2015 at 12:43 PM, Anthony Damico wrote: > > hi, ccing the package maintainer. one alternative is to pull the HU100 > > variable directly from the census bureau's summary files: that variable > > starts at position 328 and ends at 336. just modify this loop and you'll > > get a table with one-record-per-census-block in every state. > > > > https://github.com/davidbrae/swmap/blob/master/how%20to%20map%20the%20consumer%20expenditure%20survey.R#L104 > > > > (1) line 134 change the very last -9 to 9 > > (2) line 137 between "pop100" and "intptlat" add an "hu100" > > > > > > summary file docs- > > > > http://www.census.gov/pro
Re: [R] Help with Plot
Try removing the line x <- x[order(x[,1], decreasing=TRUE),] Peter On Tue, Aug 4, 2015 at 10:58 AM, April Smith wrote: > Let me just preface that everything I know about writing code for R is self > taught so this may be really basic but I can't figure it out! > > I am using someone else code to create plots. I would like to change the > automatically generated colors to the same colors for every plot. The > current code makes the highest line in the graph black, the second highest > line red, 3rd blue, etc, regardless of what the line represents. I need to > create 10 of these plots and it gets confusing when the black line means a > different thing in each plot! Here is the line I need to adjust, I just > don't know how. > > lines(1:orders, x[i,], col=i) > > Here is the code in entirety: > plot.hill <- function(x, scales = c(0, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 64, >Inf), ...) { >require(vegan) >nsites <- if(is.null(ncol(x))) 1 else ncol(x) >x <- renyi(t(x), scales=scales, hill=TRUE) >orders <- length(scales) >if(nsites > 1) { > x <- x[order(x[,1], decreasing=TRUE),] > OP <- matrix(". ", nsites,nsites) > colnames(OP) <- rownames(OP) <- rownames(x) > for(i in 1:(nsites-1)) > for(j in (i+1):nsites) > if(all(x[i,] > x[j,])) { >OP[i,j] <- "< " >OP[j,i] <- "^ " > } > diag(OP) <- " " > OP <- as.data.frame(OP) > cat("The arrow < or ^ points to the more diverse site:\n") > print(OP, na.print=" ") >} else > OP <- NULL >plot(1:4,1:4,type="n",xlim=c(0.9,orders+0.1),ylim=range(0,x),axes=FALSE, > ylab="Hill Diversity Numbers",xlab="Order", ...) >axis(2) >axis(1, at=1:orders, labels=scales) >if(nsites > 1) { > for(i in 1:nsites) > lines(1:orders, x[i,], col=i) > legend("topright", legend=row.names(x), col=1:nsites, lty=1, cex=0.7) >} else > lines(1:orders, x) >invisible(OP) > } > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Help with Plot
Let me just preface that everything I know about writing code for R is self taught so this may be really basic but I can't figure it out! I am using someone else code to create plots. I would like to change the automatically generated colors to the same colors for every plot. The current code makes the highest line in the graph black, the second highest line red, 3rd blue, etc, regardless of what the line represents. I need to create 10 of these plots and it gets confusing when the black line means a different thing in each plot! Here is the line I need to adjust, I just don't know how. lines(1:orders, x[i,], col=i) Here is the code in entirety: plot.hill <- function(x, scales = c(0, 0.25, 0.5, 1, 2, 4, 8, 16, 32, 64, Inf), ...) { require(vegan) nsites <- if(is.null(ncol(x))) 1 else ncol(x) x <- renyi(t(x), scales=scales, hill=TRUE) orders <- length(scales) if(nsites > 1) { x <- x[order(x[,1], decreasing=TRUE),] OP <- matrix(". ", nsites,nsites) colnames(OP) <- rownames(OP) <- rownames(x) for(i in 1:(nsites-1)) for(j in (i+1):nsites) if(all(x[i,] > x[j,])) { OP[i,j] <- "< " OP[j,i] <- "^ " } diag(OP) <- " " OP <- as.data.frame(OP) cat("The arrow < or ^ points to the more diverse site:\n") print(OP, na.print=" ") } else OP <- NULL plot(1:4,1:4,type="n",xlim=c(0.9,orders+0.1),ylim=range(0,x),axes=FALSE, ylab="Hill Diversity Numbers",xlab="Order", ...) axis(2) axis(1, at=1:orders, labels=scales) if(nsites > 1) { for(i in 1:nsites) lines(1:orders, x[i,], col=i) legend("topright", legend=row.names(x), col=1:nsites, lty=1, cex=0.7) } else lines(1:orders, x) invisible(OP) } [[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] Households per Census block
I had to download a bunch of stuff but I got it mostly working. Unfortunately using the alternative method I get the following: > housing<-CensusAPI2010(c("H0010001"), state.fips=state.fips, level = > c("block"), key, summaryfile = c("sf1")) Error in file(con, "r") : cannot open the connection In addition: Warning message: In file(con, "r") : cannot open: HTTP status was '400 Bad Request’ I have a feeling that this is not a problem with the API. Thanks for your help, KW > On Aug 3, 2015, at 2:12 PM, Zack Almquist wrote: > > Hi Anthony and Keith Weintraub, > > Here is a way to do what you are asking using the UScensus2010 packages: > > ## latest version of the package, not yet on CRAN > install.packages("UScensus2010", repos="http://R-Forge.R-project.org";) > library(UScensus2010) > install.blk() > library(UScensus2010blk) > ### You will want the H0010001 variable (see help(alabama.blk10)) > ### Other variables are also available > ### You can use the new api function in UScensus2010 to get arbitrary > variables from SF1 and acs > > data(states.names) > head(states.names) > state.blk.housing<-vector("list",length(states.names)) > ## notice this could be greatly spead up using the library(parallel) > ## with mclapply > ## This will be somewhat slow b/c of so much spatial data > for(i in 1:length(states.names)){ > data(list=paste(states.names[i],"blk10",sep=".")) > temp<-get(paste(states.names[i],"blk10",sep=".")) >#unique b/c more shapefiles than fips > state.blk.housing[[i]]<-unique(temp@data[,c("fips","H0010001")]) > print(i) > rm(paste(states.names,"blk10",sep=".")) > } > > ### > # alternatively Using the US Census API function in the new UScensus2010 > package > ### > > ## Get all states fips code > data(countyfips) > state.fips<-unique(substr(countyfips$fips,1,2)) > head(state.fips) > length(state.fips) ## will be 51=50 (states)+ 1(DC) > ## You will need a census key > key<-"YOUR KEY HERE" > housing<-CensusAPI2010(c("H0010001"), state.fips=state.fips, level = > c("block"), key, summaryfile = c("sf1")) > > Best, > > -- Zack > - > Zack W. Almquist > Assistant Professor > Department of Sociology and School of Statistics > Affiliate, Minnesota Population Center > University of Minnesota > > > On Mon, Aug 3, 2015 at 12:43 PM, Anthony Damico wrote: > hi, ccing the package maintainer. one alternative is to pull the HU100 > variable directly from the census bureau's summary files: that variable > starts at position 328 and ends at 336. just modify this loop and you'll get > a table with one-record-per-census-block in every state. > > https://github.com/davidbrae/swmap/blob/master/how%20to%20map%20the%20consumer%20expenditure%20survey.R#L104 > > (1) line 134 change the very last -9 to 9 > (2) line 137 between "pop100" and "intptlat" add an "hu100" > > > summary file docs- > > http://www.census.gov/prod/cen2010/doc/sf1.pdf#page=18 > > > > On Mon, Aug 3, 2015 at 11:55 AM, Keith S Weintraub wrote: > Folks, > > I am using the UScensus2010 package and I am trying to figure out the number > of households per census block. > > There are a number of possible data downloads in the package but apparently I > am not smart enough to figure out which data-set is appropriate and what > functions to use. > > Any help or pointers or links would be greatly appreciated. > > Thanks for your time, > Best, > KW > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] GARCH model estimation
I have to estimate the volatility of FTSE/MIB index with a GARCH model from 2012-06-21 to 2015-04-30, in every day. I use garchFit function, but I don't understand the meaning of se.coef output. Does this function estimate the volatility in every day of the time series (in input)? So does it estimate three parameters (for example if the model is GARCH(1,1)) in every day? Thanks for your help. Barbara [[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] attributes in dplyr and haven
Install the latest version of dplyr? Should be fixed there. Hadley On Tue, Aug 4, 2015 at 9:40 AM, Conklin, Mike (GfK) wrote: > I read in spss files using haven's read_spss. Each column then gets > attributes assigned named > label - a long description of the variable > class -" labelled" > labels --- answer labels i.e. 1=Male, 2=Female > example - >> attributes(KPTV[[3]]) > $label > [1] "DERIVED: Survey language" > > $class > [1] "labelled" > > $labels > English Spanish > 1 2 > > However, if I subset the data.frame e.g. MassTV<-KPTV[row selection logic,] > the label attribute disappears > > attributes(MassTV[[3]]) > $labels > English Spanish > 1 2 > > $class > [1] "labelled" > > If I use dplyr to filter the data I simply get an ERROR that the label > attribute is not supported. > >> MassTV<-filter(KPTV,KPTV$MNO %in% KPMass$`KPMain$mno`) > Error: column 'MNO' of type numeric has unsupported attributes: label > > Any ideas on how I can preserve the label attribute (i.e. the long > description of the variable name?) > > Thanks for any help, > > Mike > > -- > W. Michael Conklin > Executive Vice President > Marketing & Data Sciences - North America > GfK | 8401 Golden Valley Road | Minneapolis | MN | 55427 > mike.conk...@gfk.com > T +1 763 417 4545 | M +1 612 567 8287 > www.gfk.com > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. -- http://had.co.nz/ __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] write.csv file= question
On Tue, Aug 4, 2015 at 11:12 AM, Ista Zahn wrote: > On Tue, Aug 4, 2015 at 11:04 AM, John Kane wrote: >> You probably need to ask this on a RStudio forum but my guess is it is just >> a little 'refinement' that the RStudio people added. Similar in concept o >> the the matching "". > > Really? write.csv(data,”/home/data.csv”) works for me in Rstudio, ESS, > Terminal, Rscript etc. Well, actually I misspoke. I don't actually have permission to write to "/home" on my system. But write.csv(data, "~/data.csv") works. > >> >> John Kane >> Kingston ON Canada >> >> >>> -Original Message- >>> From: demmi...@gmail.com >>> Sent: Tue, 4 Aug 2015 08:51:24 -0600 >>> To: r-help@r-project.org >>> Subject: [R] write.csv file= question >>> >>> Hello, >>> >>> I have a quick question about the “file=“ specification for the command >>> write.csv.When I run this command in Rstudio I do not need the >>> “file=“ specified. For example the below command works just fine. >>> >>> write.csv(data,”/home/data.csv”) >>> >>> However when I am running an Rscript from the terminal and putting it in >>> the background I need to specify “file=“. So for the example above I >>> need to instead have >>> >>> write.csv(data,file=”/home/data.csv”) >>> >>> Any ideas why this is the case? Writing file= isn’t a problem, just >>> trying to get an idea of how R works better. >>> >>> Thanks! >>> >>> __ >>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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. >> >> >> Can't remember your password? Do you need a strong and secure password? >> Use Password manager! It stores your passwords & protects your account. >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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.
Re: [R] write.csv file= question
I cannot reproduce your problem on a Windows 8 machine with R version 3.2.1. It is working fine for me without "file=" when I source() a script file from the console. Open a script file and add the following commands: test <- data.frame(x=rnorm(15, 10, 2), y=rnorm(15, 15, 3)) write.csv(test, "test.csv") file.info("Test.csv") Save it as test.R and then source it: > source("Test.R", echo=TRUE) > test <- data.frame(x=rnorm(15, 10, 2), y=rnorm(15, 15, 3)) > write.csv(test, "test.csv") > file.info("Test.csv") size isdir mode mtime ctime Test.csv 600 FALSE 666 2015-08-04 10:13:23 2015-08-04 10:11:56 atime exe Test.csv 2015-08-04 10:11:56 no - David L Carlson Department of Anthropology Texas A&M University College Station, TX 77840-4352 -Original Message- From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Brittany Demmitt Sent: Tuesday, August 4, 2015 9:51 AM To: r-help@r-project.org Subject: [R] write.csv file= question Hello, I have a quick question about the “file=“ specification for the command write.csv.When I run this command in Rstudio I do not need the “file=“ specified. For example the below command works just fine. write.csv(data,”/home/data.csv”) However when I am running an Rscript from the terminal and putting it in the background I need to specify “file=“. So for the example above I need to instead have write.csv(data,file=”/home/data.csv”) Any ideas why this is the case? Writing file= isn’t a problem, just trying to get an idea of how R works better. Thanks! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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.
Re: [R] write.csv file= question
Call getwd() in both terminal and your RStudio environments and compare results Il 04/ago/2015 16:53, "Brittany Demmitt" ha scritto: > Hello, > > I have a quick question about the “file=“ specification for the command > write.csv.When I run this command in Rstudio I do not need the “file=“ > specified. For example the below command works just fine. > > write.csv(data,”/home/data.csv”) > > However when I am running an Rscript from the terminal and putting it in > the background I need to specify “file=“. So for the example above I need > to instead have > > write.csv(data,file=”/home/data.csv”) > > Any ideas why this is the case? Writing file= isn’t a problem, just > trying to get an idea of how R works better. > > Thanks! > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] write.csv file= question
On Tue, Aug 4, 2015 at 11:04 AM, John Kane wrote: > You probably need to ask this on a RStudio forum but my guess is it is just a > little 'refinement' that the RStudio people added. Similar in concept o the > the matching "". Really? write.csv(data,”/home/data.csv”) works for me in Rstudio, ESS, Terminal, Rscript etc. > > John Kane > Kingston ON Canada > > >> -Original Message- >> From: demmi...@gmail.com >> Sent: Tue, 4 Aug 2015 08:51:24 -0600 >> To: r-help@r-project.org >> Subject: [R] write.csv file= question >> >> Hello, >> >> I have a quick question about the “file=“ specification for the command >> write.csv.When I run this command in Rstudio I do not need the >> “file=“ specified. For example the below command works just fine. >> >> write.csv(data,”/home/data.csv”) >> >> However when I am running an Rscript from the terminal and putting it in >> the background I need to specify “file=“. So for the example above I >> need to instead have >> >> write.csv(data,file=”/home/data.csv”) >> >> Any ideas why this is the case? Writing file= isn’t a problem, just >> trying to get an idea of how R works better. >> >> Thanks! >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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. > > > Can't remember your password? Do you need a strong and secure password? > Use Password manager! It stores your passwords & protects your account. > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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.
Re: [R] write.csv file= question
Thanks! > On Aug 4, 2015, at 9:04 AM, John Kane wrote: > > You probably need to ask this on a RStudio forum but my guess is it is just a > little 'refinement' that the RStudio people added. Similar in concept o the > the matching "". > > John Kane > Kingston ON Canada > > >> -Original Message- >> From: demmi...@gmail.com >> Sent: Tue, 4 Aug 2015 08:51:24 -0600 >> To: r-help@r-project.org >> Subject: [R] write.csv file= question >> >> Hello, >> >> I have a quick question about the “file=“ specification for the command >> write.csv.When I run this command in Rstudio I do not need the >> “file=“ specified. For example the below command works just fine. >> >> write.csv(data,”/home/data.csv”) >> >> However when I am running an Rscript from the terminal and putting it in >> the background I need to specify “file=“. So for the example above I >> need to instead have >> >> write.csv(data,file=”/home/data.csv”) >> >> Any ideas why this is the case? Writing file= isn’t a problem, just >> trying to get an idea of how R works better. >> >> Thanks! >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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. > > > Can't remember your password? Do you need a strong and secure password? > Use Password manager! It stores your passwords & protects your account. > Check it out at http://mysecurelogon.com/password-manager > > __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] write.csv file= question
You probably need to ask this on a RStudio forum but my guess is it is just a little 'refinement' that the RStudio people added. Similar in concept o the the matching "". John Kane Kingston ON Canada > -Original Message- > From: demmi...@gmail.com > Sent: Tue, 4 Aug 2015 08:51:24 -0600 > To: r-help@r-project.org > Subject: [R] write.csv file= question > > Hello, > > I have a quick question about the “file=“ specification for the command > write.csv.When I run this command in Rstudio I do not need the > “file=“ specified. For example the below command works just fine. > > write.csv(data,”/home/data.csv”) > > However when I am running an Rscript from the terminal and putting it in > the background I need to specify “file=“. So for the example above I > need to instead have > > write.csv(data,file=”/home/data.csv”) > > Any ideas why this is the case? Writing file= isn’t a problem, just > trying to get an idea of how R works better. > > Thanks! > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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. Can't remember your password? Do you need a strong and secure password? Use Password manager! It stores your passwords & protects your account. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] write.csv file= question
Hello, I have a quick question about the “file=“ specification for the command write.csv.When I run this command in Rstudio I do not need the “file=“ specified. For example the below command works just fine. write.csv(data,”/home/data.csv”) However when I am running an Rscript from the terminal and putting it in the background I need to specify “file=“. So for the example above I need to instead have write.csv(data,file=”/home/data.csv”) Any ideas why this is the case? Writing file= isn’t a problem, just trying to get an idea of how R works better. Thanks! __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] attributes in dplyr and haven
I read in spss files using haven's read_spss. Each column then gets attributes assigned named label - a long description of the variable class -" labelled" labels --- answer labels i.e. 1=Male, 2=Female example - > attributes(KPTV[[3]]) $label [1] "DERIVED: Survey language" $class [1] "labelled" $labels English Spanish 1 2 However, if I subset the data.frame e.g. MassTV<-KPTV[row selection logic,] the label attribute disappears attributes(MassTV[[3]]) $labels English Spanish 1 2 $class [1] "labelled" If I use dplyr to filter the data I simply get an ERROR that the label attribute is not supported. > MassTV<-filter(KPTV,KPTV$MNO %in% KPMass$`KPMain$mno`) Error: column 'MNO' of type numeric has unsupported attributes: label Any ideas on how I can preserve the label attribute (i.e. the long description of the variable name?) Thanks for any help, Mike -- W. Michael Conklin Executive Vice President Marketing & Data Sciences - North America GfK | 8401 Golden Valley Road | Minneapolis | MN | 55427 mike.conk...@gfk.com T +1 763 417 4545 | M +1 612 567 8287 www.gfk.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] how to use nlme package to analysis mixed effect model
Dear experts, i want to use nlme or plm to analysis mixed effect model, my data has the format : city year area y x 1 2010 A 1.2 2 1 2011 A 3 3 2 2010 A 5 4 2 2011 A 2.1 1.8 3 2010 B 1.7 2 I want to know does y has relationsheep with x? how to use nlme or plm to do the task? the two packages seems does not have viggnette to guide me ? Does anyone happen to know ? -- PO SU mail: desolato...@163.com Majored in Statistics from SJTU __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] dplyr and function length() and some apologies
Dear Hadley: your request for evidence for my observation seems to have paved the way to solve this issue. As it turns out, the effect I described only occurs with "data.frames" read in with readxl. Clearly, I missed that these are tbl_df. And that explains the differential behavior depending on whether dplyr is loaded or not. Also, I realize that this latter effect can be avoided by explicitly converting objects read in with readxl to a data.frame. Well, I should have known that if i had carefully read the README stuff for readxl. But then, readxl is so much of an every-day tool for me that I didn't even think of its involvement in my problem, all the more as the reference manual does not mention the format/class of objects read in with readxl. So my apologies for any confusion I may have caused - and I certainly did not mean my observation as a charge against dplyr or its authors. Quite to the contrary, i appreciate thees tools, and as you may see, tray to understand and use them. Thank you so much again Karl On 04.08.2015 13:14, Hadley Wickham wrote: No, the effect I described has nothing to do wit USING dplyr. It occurs with >any (preexisting) data.frame once dplyr is LOADED (require(dplyr). It is >this silent, sort of "backward acting" effect that disturbs me. You're going to need to provide some evidence for that charge: dplyr does not affect the behaviour of data.frames (only tbl_dfs) Hadley -- Karl Schilling __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] Course: Introduction to zero inflated models
On Tue, Aug 4, 2015 at 7:05 AM, Highland Statistics Ltd < highs...@highstat.com> wrote: > Apologies for cross-posting > Apologies for UCE does not make it any less objectionable. But I would love a "working" vacation in the U.K. -- Schrodinger's backup: The condition of any backup is unknown until a restore is attempted. Yoda of Borg, we are. Futile, resistance is, yes. Assimilated, you will be. He's about as useful as a wax frying pan. 10 to the 12th power microphones = 1 Megaphone Maranatha! <>< John McKown [[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] Course: Introduction to zero inflated models
Apologies for cross-posting We would like to announce the following statistics course: Course: Introduction to zero inflated models Where: Elche (close to Alicante), Spain When: 2-6 November 2015 Course website: http://www.highstat.com/statscourse.htm Flyer: http://www.highstat.com/Courses/Flyers/Flyer2015_11Elche.pdf Kind regards, Alain Zuur -- Dr. Alain F. Zuur First author of: 1. Beginner's Guide to GAMM with R (2014). 2. Beginner's Guide to GLM and GLMM with R (2013). 3. Beginner's Guide to GAM with R (2012). 4. Zero Inflated Models and GLMM with R (2012). 5. A Beginner's Guide to R (2009). 6. Mixed effects models and extensions in ecology with R (2009). 7. Analysing Ecological Data (2007). Highland Statistics Ltd. 9 St Clair Wynd UK - AB41 6DZ Newburgh Tel: 0044 1358 788177 Email: highs...@highstat.com URL: www.highstat.com __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] dplyr and function length()
>> length(df[,1]). >> >> Both commands will return n. >> >> However, once dplyr is loaded, >> >> length(df[,1]) will return a value of 1. >> >> length(df$m1) and also length(df[[1]]) will correctly return n. >> >> I know that using length() may not be the most elegant or efficient way to >> get the value of n. However, what puzzles (and somewhat disturbs) me is that >> loading of dplyr affects how length() works, without there being a warning >> or masking message upon loading it. >> >> Any clarification or comment would be welcome. > > Presumably, dplyr changes how [.data.frame works (by altering the default for > drop=, I expect) so that df[,1] is a data frame with 1 variable and not a > vector. And yes, that _is_ somewhat disturbing. It changes the behaviour for [.tbl_df (tbl_df is a very minor extension of data frame with custom [ and print methods). This is partly an experiment to see what happens when you make [ more consistent - [.tbl_df always returns a data frame, so if you want a vector you have to use [[. Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] dplyr and function length()
> No, the effect I described has nothing to do wit USING dplyr. It occurs with > any (preexisting) data.frame once dplyr is LOADED (require(dplyr). It is > this silent, sort of "backward acting" effect that disturbs me. You're going to need to provide some evidence for that charge: dplyr does not affect the behaviour of data.frames (only tbl_dfs) Hadley -- http://had.co.nz/ __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] dplyr and function length()
Dear Jeff: No, the effect I described has nothing to do wit USING dplyr. It occurs with any (preexisting) data.frame once dplyr is LOADED (require(dplyr). It is this silent, sort of "backward acting" effect that disturbs me. Best, Karl Schilling On 04.08.2015 12:20, Jeff Newmiller wrote: I can confirm that the drop default is different, but keep in mind that it is only changed for a tbl_df so just convert back to data.frame at the end of your dplr operations to get back to your familiar data.frame behavior. --- Jeff NewmillerThe . . Go Live... DCN: Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On August 4, 2015 5:06:44 AM EDT, peter dalgaard wrote: > >On 04 Aug 2015, at 10:50 , Karl Schilling >wrote: > >>Dear All, >> >>I have an observation / question about how the function length() >works once package dplyr is loaded. >> >>Say we have a data.frame df with n rows and m columns. Then a way to >get the number of rows is to use >> >>length(df$m1) (m1 here stand is as the header of the first column) >> >>or, alternatively >> >>length(df[,1]). >> >>Both commands will return n. >> >>However, once dplyr is loaded, >> >>length(df[,1]) will return a value of 1. >> >>length(df$m1) and also length(df[[1]]) will correctly return n. >> >>I know that using length() may not be the most elegant or efficient >way to get the value of n. However, what puzzles (and somewhat >disturbs) me is that loading of dplyr affects how length() works, >without there being a warning or masking message upon loading it. >> >>Any clarification or comment would be welcome. > >Presumably, dplyr changes how [.data.frame works (by altering the >default for drop=, I expect) so that df[,1] is a data frame with 1 >variable and not a vector. And yes, that_is_ somewhat disturbing. > >-pd > >> >>Thank you so much, >> >>Karl >> >> >>-- >>Karl Schilling >> -- Karl Schilling __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] dplyr and function length()
I can confirm that the drop default is different, but keep in mind that it is only changed for a tbl_df so just convert back to data.frame at the end of your dplr operations to get back to your familiar data.frame behavior. --- Jeff NewmillerThe . . Go Live... DCN:Basics: ##.#. ##.#. Live Go... Live: OO#.. Dead: OO#.. Playing Research Engineer (Solar/BatteriesO.O#. #.O#. with /Software/Embedded Controllers) .OO#. .OO#. rocks...1k --- Sent from my phone. Please excuse my brevity. On August 4, 2015 5:06:44 AM EDT, peter dalgaard wrote: > >On 04 Aug 2015, at 10:50 , Karl Schilling >wrote: > >> Dear All, >> >> I have an observation / question about how the function length() >works once package dplyr is loaded. >> >> Say we have a data.frame df with n rows and m columns. Then a way to >get the number of rows is to use >> >> length(df$m1) (m1 here stand is as the header of the first column) >> >> or, alternatively >> >> length(df[,1]). >> >> Both commands will return n. >> >> However, once dplyr is loaded, >> >> length(df[,1]) will return a value of 1. >> >> length(df$m1) and also length(df[[1]]) will correctly return n. >> >> I know that using length() may not be the most elegant or efficient >way to get the value of n. However, what puzzles (and somewhat >disturbs) me is that loading of dplyr affects how length() works, >without there being a warning or masking message upon loading it. >> >> Any clarification or comment would be welcome. > >Presumably, dplyr changes how [.data.frame works (by altering the >default for drop=, I expect) so that df[,1] is a data frame with 1 >variable and not a vector. And yes, that _is_ somewhat disturbing. > >-pd > >> >> Thank you so much, >> >> Karl >> >> >> -- >> Karl Schilling >> >> __ >> R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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.
Re: [R] dplyr and function length()
On 04 Aug 2015, at 10:50 , Karl Schilling wrote: > Dear All, > > I have an observation / question about how the function length() works once > package dplyr is loaded. > > Say we have a data.frame df with n rows and m columns. Then a way to get the > number of rows is to use > > length(df$m1) (m1 here stand is as the header of the first column) > > or, alternatively > > length(df[,1]). > > Both commands will return n. > > However, once dplyr is loaded, > > length(df[,1]) will return a value of 1. > > length(df$m1) and also length(df[[1]]) will correctly return n. > > I know that using length() may not be the most elegant or efficient way to > get the value of n. However, what puzzles (and somewhat disturbs) me is that > loading of dplyr affects how length() works, without there being a warning or > masking message upon loading it. > > Any clarification or comment would be welcome. Presumably, dplyr changes how [.data.frame works (by altering the default for drop=, I expect) so that df[,1] is a data frame with 1 variable and not a vector. And yes, that _is_ somewhat disturbing. -pd > > Thank you so much, > > Karl > > > -- > Karl Schilling > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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 __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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] dplyr and function length()
Dear All, I have an observation / question about how the function length() works once package dplyr is loaded. Say we have a data.frame df with n rows and m columns. Then a way to get the number of rows is to use length(df$m1) (m1 here stand is as the header of the first column) or, alternatively length(df[,1]). Both commands will return n. However, once dplyr is loaded, length(df[,1]) will return a value of 1. length(df$m1) and also length(df[[1]]) will correctly return n. I know that using length() may not be the most elegant or efficient way to get the value of n. However, what puzzles (and somewhat disturbs) me is that loading of dplyr affects how length() works, without there being a warning or masking message upon loading it. Any clarification or comment would be welcome. Thank you so much, Karl -- Karl Schilling __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and 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.