Displaying 20 results from an estimated 36 matches for "ericstrom".
2012 Nov 22
2
Plotting specific points with type='l'
I have a dataframe (x) and I'm plotting the 5th column vs the index. I also
have a vector (v) with a few select points that I want to emphasize with a
dot for those points
> head(x)
period AP EU LA NA
1 Jan 2007 0.18 0.45 0.19 3.19
2 Feb 2007 0.14 0.48 0.36 3.55
3 Mar 2007 0.14 0.42 0.46 2.61
4 Apr 2007 0.24 0.73 0.32 4.32
5 May 2007 0.19 0.60 0.32 4.40
6 Jun 2007 0.14 0.38
2012 Nov 17
3
Reshaping a dataframe
Seems like this should be easy but I'm struggling a bit. How do I rearrange a
data frame to go from the first one to the second shown below ?
State Date lbs
TX 200701 400
TX 200702 650
TX 200703 950
TX 200704 1000
FL 200701 200
FL 200702 300
FL 200703 500
FL 200704 333
NJ 200701 409
NJ 200702 308
NJ 200703 300
NJ 200704 800
Date TX FL NJ
200701 400 200 409
200702 650
2011 May 26
2
What am I doing wrong with sapply ?
Statement 9 using sapply does not seem to give the correct answer (or at
least to me). Yet I do what I think is the same thing with statement 11 and
I get the answer I'm looking for.
9 : s <-sapply(unlist(v[c(1:length(v))]), max)
11: for(i in 1 :length(v)) v1[i] <- max(unlist(v[i]))
Shouldn't I get the same answer ?
library(XML)
rm(list=ls())
url <-
2012 Nov 18
3
Replace <NA> with something else
I am reading some data into R from an Excel spreadsheet using read.csv. Some
of the original data that comes into column 1 from the spreadsheet is text
that says NA. The NA stands for north america. As it comes in, R converts
the NA over to <NA>.
What is the cleanest way to change the <NA> values to something else. In
other words, get rid of the brackets ? Maybe convert <NA>
2011 Jan 30
3
How to do a moving window on standard deviation
I'd like to use vectorization to take a 4 point moving window on standard
deviation on the close column and create another variable (st.dev) in the
dataframe. Here's the dataframe
head(xyz)
Date Close
1 2011-01-28 56.42
2 2011-01-27 57.37
3 2011-01-26 56.48
4 2011-01-25 56.39
5 2011-01-24 55.74
6 2011-01-21 55.46
So the first 3 elements to the new st.dev column would be zero
2011 Jul 05
2
Stuck ...can't get sapply and xmlTreeParse working
Can't seem to get the code below working. It gets stuck on line 24 inside the
function hm; comments show the line in question. The function hm is called
by sapply and is at the bottom of the code. Other stuff above line 24 works
correctly including the first couple of lines of the function hm. Should I
be using a different apply function or am I doing something wrong with
xmlTreeParse ?
2011 Apr 29
3
why doesn't ifelse work ?
I have the following lines of code:
ind <- rollapply(GSPC, 200, mean)
signal <- ifelse(diff(ind, 5) > 0 , 1 , -1)
signal[is.na(signal)] <- 0
I never get a value of -1 for signal even though I know diff(ind , 5) is
less than zero frequently. It looks like when diff(ind , 5) is less than
zero, signal gets set to 0 instead of - 1. Any ideas why ? Here's some
information on ind and
2010 Nov 29
1
How do I subtract sequential values ?
Just starting to learn R so excuse me if this is a simple question. I'm
wondering how I get the percent difference in sequential values in one
column of a dataframe. If I had a dataframe and one of the columns was
"value", how would I go about calculating (v2-v1)/v1 ....(v3-v2)/v2
....(v4-v3)/v3 ...etc ?
--
View this message in context:
2010 Dec 27
1
package update
I'm running Linux Ubuntu and tried to update my packages using the
update.package() command. It appeared to download the updates ok but I got
the following message:
The downloaded packages are in ?/tmp/RtmpFM82Ry/downloaded_packages?
Warning in install.packages(update[instlib == l, "Package"], l, contriburl =
contriburl, :
'lib = "/usr/lib/R/site-library"' is
2011 Apr 03
1
How do I modify uniroot function to return .0001 if error ?
I am calling the uniroot function from inside another function using these
lines (last two lines of the function) :
d <- uniroot(k, c(.001, 250), tol=.05)
return(d$root)
The problem is that on occasion there's a problem with the values I'm
passing to uniroot. In those instances uniroot stops and sends a message
that it can't calculate the root because f.upper * f.lower is greater
2011 Feb 27
1
Plotting two lines on a graph when using par(mfrow=)
Basic question but still learning ....
How do I plot two lines (f$equity and f$bh.equity) on one of the three
graphs under mfrow ? I tried putting brackets around the first plot and
lines command but that didn't work.
par(mfrow=c(3,1))
{plot(f$Date,f$equity, col="blue", type="l", main="equity")
lines(f$bh.equity, col="gray")}
plot(f$Date,f$indicator,
2011 May 15
1
Need help with text processing / string split
I used screen scraping to extract some information and put it into a table
called tbl. Now I want to modify the table a bit so the data can be more
useful. Here's the code I used:
library(XML)
rm(list=ls())
url <-
"http://webapp.montcopa.org/sherreal/salelist.asp?saledate=05/25/2011"
tbl <-data.frame(readHTMLTable(url))[2:405, c(3,5,6,8,9)]
names(tbl) <-
2012 Nov 16
2
Dealing with factors ???
I have a data frame x that came from read.csv. It seemed to read in ok but
then I tried doing some plotting of the values and ran into difficulties.
The plot command seems to be plotting factors instead of the values. How do
I get rid of these factors ? The plot command I use is : plot (x$dat, x$TX,
type='l'). I also tried ...plot(x$dat, levels(x$TX), type='l) but got an
error :
2011 Aug 14
3
Not sure how to use aggregate, colSums, by
I have a data frame called test shown below that i would like to summarize in
a particular way :
I want to show the column sums (columns y ,f) grouped by country (column
e1). However, I'm looking for the data to be split according to column e2.
In other words, two tables of sum by country. One table for "con" and one
table for "std" shown in column e2. Finally at the
2011 Nov 05
2
install.packages problem
I'm trying to install the rdatamarket package. I did an
install.packages('rdatamarket') command but got an error about half way
through the install as follows:
* installing *source* package ?RCurl? ...
checking for curl-config... no
Cannot find curl-config
ERROR: configuration failed for package ?RCurl?
The install continued after the error but looks like it was completed. I'm
2011 Jan 17
2
data frame column name change
How do I change the name of one column in a data frame ? Suppose I have a
data frame x with 5 columns. If the names were date, col1, col2, col3, col4
and I wanted to simply change the name of date, what would the command be ?
I tried the following and it didn't seem to work :
names(x[1]) <- "newname"
Thanks in advance for the comments
--
View this message in context:
2011 Jan 17
1
Log difference in a dataframe column
What am I doing wrong here ? And what's the right way to calculate the log
differences in a column in a df ?
# first 3 rows of 5000 rows
y[1:3,]
Date Open High Low Close
1 1983-03-30 29.96 30.51 29.96 30.35
2 1983-03-31 30.35 30.55 30.20 30.24
3 1983-04-04 30.25 30.65 30.24 30.39
#equation in question ...why is this giving zeros ?
y1 <- 100*log(y[,5]/(lag(y[,5],1)))
# first 10
2011 Jul 10
1
Help with tryCatch
Having a hard time understanding the help files for tryCatch. Looking for a
little help with the following statement which sits inside a for loop
zest[i] <- tryCatch(sapply(getNodeSet(zdoc, "//zestimate/amount"),
xmlValue), error=function() zest[i] <-"NA")
zest is a numeric vector
If the sapply statement evaluates to an error, I'd like to set the value of
zest[i]
2011 Jan 27
1
How do I fix this ?
Just when I think I'm starting to learn ....
Statement z1 works, statement z doesn't. Why doesn't z work and what do I do
to fix it ? Clearly the problem is with the first NA, but I would think it's
handled through the loop vectorization.
y1 <- rnorm(20, 0, .013)
y1
[1] -0.0068630836 -0.0101106230 -0.0169663344 -0.0066314769 0.0075063818
[6] -0.0033548024 0.0015647863
2011 May 08
1
package update
I tried to update my packages using update.packages()
I got the following message:
The downloaded packages are in
?/tmp/RtmpyDYdTX/downloaded_packages?
Warning in install.packages(update[instlib == l, "Package"], l, contriburl =
contriburl, :
'lib = "/usr/lib/R/library"' is not writable
Error in install.packages(update[instlib == l, "Package"], l,