Displaying 20 results from an estimated 10000 matches similar to: "indexing list elements with lapply?"
2012 Nov 09
5
using lapply with recode
Hello:
Forgive me, this is surely a simple question but I can't figure it out, having consulted the help archives and "Data Manipulation With R" (Spector).
I have a list of 11 data frames with one common variable in each (prov). I'd like to use lapply to go through and recode one particular level of that common variable.
I can get the recode to work, but it only returns the
2011 Jan 17
1
Importing multiple text files with lapply.
Hello,
I'm trying to read in 50 text filess with dates as content to create a list of tables.
a is the list of filenames that need to be read in.
The following command returns the following error
mylist<-lapply(a, read.table(header=TRUE, sep="\n"))
Error in read.table(header = TRUE, sep = "\n") :
element 1 is empty;
the part of the args list of
2010 Oct 10
1
Create single vector after looping through multiple data frames with GREP
Hello all,
I changed the subject line of the e-mail, because the question I''m posing now is different than the first one. I hope that this is proper etiquette. However, the original chain is included below.
I've incorporated bits of both Ethan and Brian's code into the script below, but there's one aspect I can't get my head around. I'm totally new to programming
2010 Oct 19
2
separate elements of a character vector
Dear colleagues, this seems like an easy problem, and I found some suggestions which I've incorporated in the help list, but I can't quite get it right.
I want to add a series of years to a second x-axis category label. I generate them with test and test_2 below, format them with some spacing (which is the suggestion I took from the R-list) and concatenate them and then write them with
2012 May 28
1
Rcurl, postForm()
Dear colleagues,
Could I get some assistance using postForm() to scrape the business names and addresses at this website:
http://www.brantford.ca/business/LocalBusinessCommunity/Pages/BusinessDirectorySearch.aspx
I've read through (http://www.omegahat.org/RCurl/RCurlJSS.pdf) and scoured the web for tutorials, but I can't crack it. I'm aware that this is probably a pretty basic
2011 Jul 28
2
cycling from x11 window in RCommander to graphics device window: Mac Os 10.6.8
Dear Colleagues,
I have recently installed R Commander on my Mac OS 10.6.8. I'd like to use it for an undergraduate class this year.
Everything appears to be working fine, except for one thing. I cannot use Command-tab to cycle from the X11 window in which RCommander is running to any other window open in my workspace. This is particularly important because I cannot cycle to the graphics
2012 Aug 20
2
Changing line length in Sweave output works for numeric, but not for character vectors
Hi there: I'm preparing a report in RStudio 0.96.330 on a Mac OS. I'm running R 2.15.0
I understand from Ross Ihaka's document (http://www.stat.auckland.ac.nz/~stat782/downloads/Sweave-customisation.pdf) that you can modify the line length of Sweave output by a call to options(wdith=x).
This works great for me for numeric output, but not for character vectors that I have to print.
2011 Nov 10
2
Listing tables together from random samples from a generated population?
.
HI there,
I'd like to show demonstrate how the chi-squared distribution works, so I've come up with a sample data frame of two categorical variables
y<-data.frame(gender=sample(c('Male', 'Female'), size=100000, replace=TRUE, c(0.5, 0.5)), tea=sample(c('Yes', 'No'), size=100000, replace=TRUE, c(0.5, 0.5)))
And I'd like to create a list of 100
2011 Jan 18
2
Counting dates in arbitrary ranges
Dear Colleagues,
I have a data set that looks as below. I'd like to count the number of dates in a series of arbitrary ranges (breaks) i.e. not pre-defined breaks such as months, quarters or years. table(format()) produces ideally formatted output, but table() does not appear to accept arbitrary ranges.
I also tried converting the dates to numeric and using histogram to try to get the data,
2012 Mar 12
3
lapply to change variable names and variable values
Hi: I'm sure this is a very easy problem. I've consulted Data Manipulation With R and the R Book and can't find an answer.
Sample list of data frames looks as follows:
.xx<-list(df<-data.frame(Var1=rep('Alabama', 400), Var2=rep(c(2004, 2005, 2006, 2007), 400)), df2<-data.frame(Var1=rep('Tennessee', 400), Var2=rep(c(2004,2005,2006,2007), 400)),
2012 Apr 16
1
grep and XML
Hi all:
I struggle a lot scraping web data. I still haven't got a handle on the XML package.
I'd like to get particular exchange rates from this table:
https://raw.github.com/currencybot/open-exchange-rates/master/latest.json
This is the code that I'm working with:
library(RCurl)
library(XML)
2011 Jul 11
1
grep lines before or after pattern matched?
Dear colleagues,
I have a series of newspaper articles in a text file, downloaded from a text file. They look as follows:
Document 1 of 100
\n
\n
\n
Newspaper Name
\n
\n
Day Date
I have a series of grep scripts that can extract the date and convert it to a date object, but I can't figure out how to grep the newspaper name. There is no field ID attached to those lines. The best I can come
2011 Jan 25
1
subsetting based on joint values of critera
Dear colleagues, I have a dataset that looks as below.
I would like to make a new dataset that excludes the cases which are joint conjunctions of particular state names and years, so Connecticut and 2010, Maryland and 2010 and Vermont and 2010.
I'm trying the following subset code:
newdata<- subset(bpa, (!State=="Connecticut" & year<"2010"))
It appears that
2011 Mar 31
1
error in recode.defalt ....object '.data' not found
Dear colleagues, working with the data frame below, trying to reverse two variables I the error message below.
i searched through the help list but could not find any postings which could help me solve the situation. I tried attaching and detaching the data frame to no avail.
Yours, Simon Kiss
*DATA FRAME
'data.frame': 1569 obs. of 9 variables:
$ equal : num 3 4 3 2 3 4 2 3 2 2 ...
2011 Jul 23
2
sum part of a vector
Dear colleagues, I have a data set that looks roughly like this;
mydat<-data.frame(state=c(rep("Alabama", 5), rep("Delaware", 5), rep("California", 5)), news=runif(15, min=0, max=8), cum.news=rep(0, 15))
For each state, I'd like to cumulatively sum the value of "news" and make that put that value in cum.news.
I'm trying as follows but I get
2006 Aug 14
1
Lattice barchart with different fill pattern
Dear list,
I am new to lattice plots.
I want to make a barchart with 10 and more levels.
I need to use a grey scale for printing purposes.
The problem is that with 10 or more levels in factors it is very
difficult to distinguish each level in the plot and legend, since the
greys are very similar (some levels have value of zero and don't appear).
Here is an example of my problem:
df <-
2010 Sep 21
2
group means of multi-way table?
hello, can someone tell me how to generate the means for a data frame
that looks like this? My data frame has many more variables, but I
won't bother you with those; these are the one's that I'm interested in.
Needless to say, z is the variable in which I'm interested. I'd like
to find out the mean score of z for NDP managers, Conservative
managers and Liberal managers
2010 Oct 06
2
Converting scraped data
Dear Colleagues,
I used this code to scrape data from the URL conatined within. This
code should be reproducible.
require("XML")
library(XML)
theurl <- "http://www.queensu.ca/cora/_trends/mip_2006.htm"
tables <- readHTMLTable(theurl)
n.rows <- unlist(lapply(tables, function(t) dim(t)[1]))
class(tables)
test<-data.frame(tables, stringsAsFactors=FALSE)
2013 Mar 15
2
latex(test, collabel=) returns wrong latex code?
Hello:
I'm working with a 2-dimensional table that looks sort of like test below.
I'm trying to produce latex code that will add dimension names for both the rows and the columns.
In using the following code, latex chokes when I include collabel='Vote' but it's fine without it.
The code below prouces the latex code further below. I'm confused by this, because it looks
2011 Sep 05
2
htmlParse hangs or crashes
Dear colleagues,
each time I use htmlParse, R crashes or hangs. The url I'd like to parse is included below as is the results of a series of basic commands that describe what I'm experiencing. The results of sessionInfo() are attached at the bottom of the message.
The thing is, htmlTreeParse appears to work just fine, although it doesn't appear to contain the information I need (the