similar to: creating a data frame from a list

Displaying 20 results from an estimated 10000 matches similar to: "creating a data frame from a list"

2007 Apr 05
2
creating a data frame from a list
Dear all, A few months ago, I asked for your help on the following problem: I have a list with three (named) numeric vectors: > lst = list(a=c(A=1,B=8) , b=c(A=2,B=3,C=0), c=c(B=2,D=0) ) > lst $a A B 1 8 $b A B C 2 3 0 $c B D 2 0 Now, I'd love to use this list to create the following data frame: > dtf = data.frame(a=c(A=1,B=8,C=NA,D=NA), +
2006 Jul 12
1
help in vectorization
Hi, I have two data frames. One is like > dtf = data.frame(y=c(rep(2002,4), rep(2003,5)), + m=c(9:12, 1:5), + def=c(.74,.75,.76,.78,.80,.82,.85,.85,.87)) and the other dtf2 = data.frame(y=rep( c(2002,2003),20), m=c(trunc(runif(20,1,5)),trunc(runif(20,9,12))), inc=rnorm(40,mean=300,sd=150) ) What I want is to divide
2005 Oct 20
5
spliting an integer
Hi there, From the vector X of integers, X = c(11999, 122000, 81997) I would like to make these two vectors: Z= c(1999, 2000, 1997) Y =c(1 , 12 , 8) That is, each entry of vector Z receives the four last digits of each entry of X, and Y receives "the rest". Any suggestions? Thanks in advance, Dimitri [[alternative HTML version deleted]]
2005 Oct 25
2
Inf in regressions
Hi, Suppose I I wish to run lm( y ~ x + z + log(w) ) where w assumes non-negative values. A problem arises when w=0, as log(0) = -Inf, and R doesn't accept that (as it "accepts" NA). Is there a way to tell R to do with -Inf the same it does with NA, i.e, to ignore it? ( Otherwise I have to do something like w[w==0] <- NA which doesn't hurt, but might be a bit
2006 Jan 26
1
efficiency with "%*%"
Hi, x and y are (numeric) vectors. I wonder if one of the following is more efficient than the other: x%*%y or sum(x*y) ? Thanks, Dimitri Szerman
2006 Apr 29
1
splitting and saving a large dataframe
Hi, I searched for this in the mailing list, but found no results. I have a large dataframe ( dim(mydata)= 1297059 16, object.size(mydata= 145280576) ) , and I want to perform some calculations which can be done by a factor's levels, say, mydata$myfactor. So what I want is to split this dataframe into nlevels(mydata$myfactor) = 80 levels. But I must do this efficiently, that is, I
2006 Apr 26
1
help using tapply
Dear R-mates, # Here's what I am trying to do. I have a dataset like this: id = c(rep(1,8), rep(2,8)) dur1 <- c( 17,18,19,18,24,19,24,24 ) est1 <- c( rep(1,5), rep(2,3) ) dur2 <- c(1,1,3,4,8,12,13,14) est2 <- rep(1,8) mydata = data.frame(id, estat=c(est1, est2), durat=c(dur1, dur2)) # I want to one have this: id = c(rep(1,8), rep(2,8))
2007 Apr 06
2
lm() intercept at the end, rather than at the beginning
Hi, I wonder if someone has already figured out a way of making summary(mylm) # where mylm is an object of the class lm() to print the "(Intercept)" at the last line, rather than the first line of the output. I don't know about, say, biostatistics, but in economics the intercept is usually the least interesting of the parameters of a regression model. That's why, say, Stata
2005 Jun 24
2
Gini with frequencies
Hi there, I am trying to compute Gini coefficients for vectors containing income classes. The data I possess look loke this: yit <- c(135, 164, 234, 369) piit <- c(367, 884, 341, 74 ) where yit is the vector of income classes, and fit is the vector of associated frequencies.(This data is from Rustichini, Ichino and Checci (Journal of Public Economics, 1999) ). In ineq pacakge, Gini( )
2010 Mar 02
1
simple data transformation question
Hi all, I have a (hopefully) simple newbie-level question.   # I have data like this: dtf <- data.frame(read.table(textConnection("var  value   company  9887.1   company  91117.0   blaah  91.1   etc  11   etc  97111"), header=TRUE))   # I would like to have output like this (the index number may vary): var  value.1 value.2 company 9887.1 91117.0 blah  91.1 NA etc 11 97111   # I
2006 Nov 30
1
data.frame within a function (PR#9294) (cont'd)
This continues the message "data.frame within a function (PR#9294)" that was posted on 2006/10/12. Duncan Murdoch kindly replied. I'm using the current version R 2.4.0, but the same issue exists. Just copy and paste the following code under R, and compare the output of f1() and f2() and the output of f3() and f4(). Does anybody have any idea? Thanks.
2009 Nov 15
1
R crashing
Hello, This is what I am trying to do: I wrote a little function that takes addresses (coordinates) as input, and returns the road distance between every two points using Google Maps. Catch is, there are 2000 addresses, so I have to get around 2x10^6 addresses. On my first go, this is what I did: ######################################### getRoadDist = function(X,complete=F){ # X must be a
2018 Jun 01
1
rasterize SpatialPolygon object using a RasterBrick object
I am trying to rasterize a SpatialPolygon object by a RasterBrick object. The documentation of the raster::rasterize function explicitly says this is allowed. Here's what I am doing # load the raster package library("raster") # create a raster brick object using the example from the brick function documentation b <- brick(system.file("external/rlogo.grd",
2006 Oct 04
1
extracting nested variances from lme4 model
I have a model: mod1<-lmer( x ~ (1|rtr)+ trth/(1|cs) , data=dtf) # Here, cs and rtr are crossed random effects. cs 1-5 are of type TRUE, cs 6-10 are of type FALSE, so cs is nested in trth, which is fixed. So for cs I should get a fit for 1-5 and 6-10. This appears to be the case from the random effects: > mean( ranef(mod1)$cs[[1]][1:5] ) [1] -2.498002e-16 > var(
2011 Sep 27
2
Coercing a character zoo to a numeric
Dear R-helpers, It seems to me that a character zoo cannot be coerced to a numeric zoo. Below is a minimal example. Can someone tell me what I have done wrong? > z<-zoo(1:4,order.by=1:4) > coredata(z)<-as.character(coredata(z)) > str(z) ‘zoo’ series from 1 to 4 Data: chr [1:4] "1" "2" "3" "4" Index: int [1:4] 1 2 3 4 >
2009 May 12
2
import HTML tables
Hello, I was wondering if there is a function in R that imports tables directly from a HTML document. I know there are functions (say, getURL() from {RCurl} ) that download the entire page source, but here I refer to something like google document's function importHTML() (if you don't know this function, go check it, it's very useful). Anyway, if someone of something that does this
2009 Jun 19
1
(FULL) Need help to optimize a piece of code involving zoo objects
(Sorry, sent the message before I finished it) Hello, everyone I have a long script that uses zoo objects. In this script I used simple moving averages and these I can very efficiently calculate with filter() functions. Now, I have to use special "exponential" moving averages, and the only way I could write the code was with a for-loop, which makes everything extremely slow. I don't
2009 Jun 19
1
Need help to optimize a piece of code involving zoo objects
Hello, everyone I have a long script that uses zoo objects. In this script I used simple moving averages and these I can very efficiently calculate with filter() functions. Now, I have to use special "exponential" moving averages, and the only way I could write the code was with a for-loop, which makes everything extremely slow. I don't know how to optimize the code, but I need to
2008 Oct 22
1
R 2.8.0 qqnorm produces error with object of class zoo?
Dear list-reader, by running the following script: library(zoo) sessionInfo() search() packageDescription("zoo") data(EuStockMarkets) dax <- as.zoo(EuStockMarkets[1:10, "DAX"]) daxr <- diff(log(dax)) identical(as.vector(qnorm(daxr)), qnorm(coredata(daxr))) qqnorm(coredata(daxr)) qqnorm(daxr) qqnorm() produces an error: > qqnorm(daxr) Fehler in if (xi == xj) 0L
2011 Apr 04
2
merging 2 frames while keeping all the entries from the "reference" frame
Hello! I have my data frame "mydata" (below) and data frame "reference" - that contains all the dates I would like to be present in the final data frame. I am trying to merge them so that the the result data frame contains all 8 dates in both subgroups (i.e., Group1 should have 8 rows and Group2 too). But when I merge it it's not coming out this way. Any hint would be