Displaying 20 results from an estimated 2000 matches similar to: "Extending data frame with longer columns"
2013 Apr 26
1
Stratified Random Sampling Proportional to Size
Hello R Experts,
I kindly request your assistance on figuring out how to get a stratified random sampling proportional to 100.
Below is my r code showing what I did and the error I'm getting with sampling::strata
# FIRST I summarized count of records by the two variables I want to use as strata
Library(RODBC)
library(sqldf)
library(sampling)
#After establishing connection I query the data
2007 Nov 08
3
skip non-sequential lines using scan?
Hi all,
Is there a way to skip non-sequential lines using the "skip" argument
in the scan function?
E.g., I have a matrix with 100 rows and 1e7 columns. I open a
connection and want to read only lines 5, 7, 9, etc [i.e.,
seq(5,99,2)]
It might seem that the syntax to do this would be something like this
(if only the "skip" allowed vectors in the same way colClasses does in
2012 Jan 27
3
Subsetting for the ten highest values by group in a dataframe
Hello,
I am looking for a way to subset a data frame by choosing the top ten
maximum values from that dataframe. As well this occurs within some
factor levels.
## I've used plyr here but I'm not married to this approach
require(plyr)
## I've created a data.frame with two groups and then a id variable (y)
df <- data.frame(x=rnorm(400, mean=20), y=1:400,
2010 Dec 07
4
Creating binary variable depending on strings of two dataframes
Hi,
consider the following two dataframes:
x1=c("232","3454","3455","342","13")
x2=c("1","1","1","0","0")
data1=data.frame(x1,x2)
y1=c("232","232","3454","3454","3455","342","13","13","13","13")
2011 Dec 12
3
obtener variables desde un dataframe
Hola amigos de R en Español,
Estoy eliguiendo unas variables desde una dataframe, pero cuando creo un objeto nuevo ( con cbind) las nueva tabla (que es una matriz) se pierden los nombres de los factores. Aparecen numeros (1,2,3..).
Alguien me puede decir si existe un comando para extraer las variables a un nuevo dataframe, pero sin cambiar el nombre, ni la codificacion ?
Gracias,
José
2011 Apr 27
6
Assignments inside lapply
Dear all I would like to ask you if an assignment can be done inside a lapply statement.
For example
I would like to covert a double nested for loop
for (i in c(1:dimx)){
for (j in c(1:dimy)){
Powermap[i,j] <- Pr(c(i,j),c(PRX,PRY),f)
}
}
to something like that:
ij<-expand.grid(i=seq(1:dimx),j=(1:dimy))
unlist(lapply(1:nrow(ij),function(rowId) { return
2009 Aug 12
4
paste first row string onto every string in column
Hi,
I am trying to edit a data frame such that the string in the first line is
appended onto the beginning of each element in the subsequent rows. The data
looks like this:
> df
V1 V2 V3 V4
1 DPA1* DPA1* DPB1* DPB1*
2 0103 0104 0401 0601
3 0103 0103 0301 0402
.
.
and what I want is this:
>dfnew
V1 V2 V3 V4
1 DPA1* DPA1* DPB1* DPB1*
2 DPA1*0103
2008 Jan 24
2
boxplot axis labelling
Hi,
i'm very new to R, so sorry for what i'm sure is a very basic question. I'm
producing a boxplot with the data below:
df3<-data.frame(
x=c(10,11,115,12,13,14,16,17,18,21,22,23,24,26,27,28,29,3,30,32,33,34,35,4,4
1,45,5,50,52,56,58,6,67,6738,68,7,8,9),
fq=c(8,11,1,2,4,4,2,2,6,3,4,2,2,1,1,1,4,51,3,1,1,1,1,35,1,1,19,2,1,1,1,14,1,
1,1,10,13,5),
2017 Nov 01
3
Adding Records to a Table in R
Dear R friends,
I am currently working with time series data, and I have a table(as data
frame) that has looks like this (TransitDate are in format = "%e-%B-%Y") :
TransitDate Transits CargoTons
1985-04-01 100 2500
1985-05-01 135 4500
1985-06-01 120 1750
1985-07-01 100 3750
1985-08-01 200
2010 Apr 21
2
Table to List Transformation Scenario
I have a series of tables, one for each environment indicating a date (row)
and a sample at each hour of the day (0 to 23)
Test1 Table:
Date,Hour1,Hour2,...Hour23
1/1/10,123,123,...,123
I would like to model this as a time series but how can I translate the
table into a list such that I can get:
1/1/10 00:00, 123
1/1/10 01:00, 123
1/1/10 02:00, 123
...
1/1/10 23:00, 123
Any suggestions on how
2010 Mar 12
1
Length as fun.aggregate in cast function of reshape package: unexpected error
Dear Everyone,
I am having problems with use of the reshape package's cast function using length as an aggregating function.
Unexpectedly, I receive the error: 2 arguments passed to 'length' which requires 1
I don't understand this at all - the data I'm using is very simple, and appears almost identical to that used in the
ChickWeight example in the package. The problem can
2017 Nov 01
0
Adding Records to a Table in R
Hi Paul,
#First I set up some sample data since I don't have a copy of your data
dtOrig <- as.Date( c("1985-04-01","1985-07-01","1985-12-01","1986-04-01"))
dfOrig <- data.frame( TransitDate=dtOrig, Transits=c(100,100,500,325),
CargoTons=c(1000,1080,3785,4200) )
#Generate the complete set of dates as a data frame
dfDates<- data.frame(
2008 May 03
1
recode involving a count rule
Hello, R-helpers.
I have a data frame below called df. I want to add a variable c, based on
the following logic:
if df$a < 5 then the first two times this condition is met place a 1 in c,
the next two times this condition is met place a 2 in c and when the
condition is not met let c equal df$b. The result would look like, dfnew,
shown below.
a <- rep(c(3,5,7), 4)
b <- rep(c(NA,1,2),
2010 Feb 08
1
R ggplot2 legend text left justify
In ggplot2 how do you justify the legend text ?
In the example below the opts(legend.text = theme_text(size =
9,hjust=0)) changes the size of the text OK but it remains right
justified.
> mydata=data.frame(RowID=c("A","B","C"),Name=c("long long long long
long name","short name ","medium medium name"),Speed=c(100,140,120))
>
2012 Aug 17
2
How can we compare corresponding values of x and y (first value of x exacly matches with the first value of y)?
df <- data.frame (
"RowId" = 4:7,
"x"=c("1_1", "2_2", "3_3", "3_3"),
"y"=c("1_1", "3_3", "2_2", "3_3")
)
How can we compare corresponding values of x and y (first value of x exacly matches with the first value of y)?
If they were not matced
2020 Sep 24
1
How to use `[` without evaluating the arguments.
Hello R-devel,
I am currently attempting to implement an API similar to data.table wherein single bracket subsetting can accept an unquoted expression to be evaluated in the context of my object.
A simple example from the data.table package looks like this:
DT <- data.table(col1 = c('a', 'b', 'c'), col2 = c('x', 'y', 'z'))
DT[col1 ==
2013 Apr 09
4
Converting matrix to data frame without losing an assigned dimname
Hello All,
Would like to be able to convert a matrix to a dataframe without losing an assigned dimname.
Here is an example that should illustrate what I'm talking about.
tableData <- state.x77[c(7, 38, 20, 46), c(7, 1, 8)]
names(dimnames(tableData)) <- c("State", "")
tableData
State Frost Population Area
Connecticut 139 3100 4862
2017 Nov 08
3
Adding Records to a Table in R
Dear Eric,
Hope you are doing great. I also tried the following:
#First I created the complete date sequence
TransitDateFrame <- data.frame(TransitDate=seq(as.Date(dataset1[1,1]),
as.Date(dataset1[nrow(dataset1),1]), by = "month"))
#Then I did the merging
dataset1NEW <- merge(TransitDateFrame, dataset1, by="TransitDate",
all.x=TRUE)
Now it has, as expected the
2012 Mar 07
1
SELECT CASE in RODBC
Hi all,
I have a problem with a variable created by a SELECT CASE statement. See
the code below.
I would like the variable "event" to be a character variabel as I want to
UNION my two SELECTs - and the "event"-variable is a character variable in
the first SELECT result.
I have tried different ways:
* used ' ' in stead of " " around the string I want as the
2006 Jan 16
8
AJAX + Table.
Hello all.
I am trying ot load table rows using AJAX based on a search. The
following code results in:
1. Firefox renders correctly (Multiple rows inserted into page).
2. Opera renders the entire returned string in one <td> by the looks of
it (Bunched up under first header, the <> tags arne''t visible)
3. IE6 does nothing....great ;)
This is driving me nuts so any help