Displaying 20 results from an estimated 153 matches for "df3".
Did you mean:
df
2008 Jan 10
2
`[.data.frame`(df3, , -2) and NA columns
...orkarounds" required, just curious.
Dieter
Version: Windows, R version 2.6.1 (2007-11-26)
#-----------------------------
df = data.frame(a=0:10,b=10:20)
df[,-2] #ok
names(df)=c("A") # implicitly creates an NA column
df[,-2]
df[,-2,drop=FALSE] # has nothing to do with drop
df3 = data.frame(a=0:10,b=10:20,c=20:30)
df3[,-2] #ok
names(df3)=c("A","B") #creates an NA column
df3[,-2] # error
# Error in `[.data.frame`(df3, , -2) : undefined columns selected
names(df3)[3]="NaN" # another reserved word
df3[,-2] # no problem
2009 Jan 21
3
merging several dataframes from a list
...iple files) and all
dataframes are comparable in dimension and column names. They also have a
common column, which, I'd like to use for merging. To give a simple example of
what I have:
df1 <- data.frame(c(LETTERS[1:5]), c(2,6,3,1,9))
names(df1) <- c("pos", "data")
df3 <- df2 <- df1
df2$data <- c(6,2,9,7,5)
df3$data <- c(9,3,6,2,1)
mylist <- list(df1,df2,df3)
names(mylist) <- c("df1","df2","df3")
> mylist
$df1
pos data
1 A 2
2 B 6
3 C 3
4 D 1
5 E 9
$df2
pos data
1 A 6
2 B...
2011 Aug 18
2
Best way/practice to create a new data frame from two given ones with last column computed from the two data frames?
...2[sample(1:nrow(df2)),])
## Now I would like to create a third data frame that has "Year" in column one,
## "Group" in column two, and each entry of column three should consist of the
## corresponding entry in df1 divided by the one in df2.
## To achieve this, one could do:
df3 <- df1[with(df1, order(Year,Group)),]
df3$Value <- df3$Value/df2[with(df2, order(Year,Group)),]$Value
colnames(df3)[3] <- "New Value" # typically, the column name changes
## or one could do:
df3 <- df1[with(df1, order(Year,Group)), -ncol(df1)]
df3 <- cbind(df3, "New...
2008 Feb 19
2
Looping through a list of objects & do something...
Hey Folks,
Could somebody show me how to loop through a list of dataframes? I want to
be able to generically access their elements and do something with them.
For instance, instead of this:
df1<- data.frame(x=(1:5),y=(1:5));
df2<- data.frame(x=(1:5),y=(1:5));
df3<- data.frame(x=(1:5),y=(1:5));
plot(df1$x,df1$y);
plot(df2$x,df2$y);
plot(df3$x,df3$y);
I would like to do something like:
(pseudocode)
dfarray[1] = df1
dfarray[2] = df2
dfarray[3] = df3
for (each i in dfarray) {
plot(i$x, i$y);
}
Can this be done in R?
Thanks.
Tripp
--
View this message...
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),
fqcvd=c(5,8,1,1,3,3,2,2,5,3,4,2,2,0,1,1,3,13,2,1,1,1,1,17,1,...
2008 Jul 26
1
Can't get the correct order from melt.data.frame of reshape library.
Simple illustration,
> df3 <- data.frame(id=c(3,2,1,4), age=c(40,50,60,50), dose1=c(1,2,1,2), dose2=c(2,1,2,1), dose4=c(3,3,3,3))> df3 id age dose1 dose2 dose41 3 40 1 2 32 2 50 2 1 33 1 60 1 2 34 4 50 2 1 3> melt.data.frame(df3, id.var=1:2, na.rm=T) id age...
2010 May 11
2
Regex and gsub
Dear group,
Here is my df :
df3 <-
structure(list(DESCRIPTION = c("COPPER May/10", "COTTON NO.2 Jul/10",
"CRUDE OIL miNY May/10", "GOLD Jun/10", "ROBUSTA COFFEE (10) Jul/10",
"SOYBEANS Jul/10", "SUGAR NO.11 Jul/10", "SUGAR NO.11 May/10",
"W...
2009 Oct 07
1
merging dataframes with an unequal number of variables
...2,3,4,5,6)
var2=c("a","b","a","b","a","a")
var3=c(1,NA,NA,2,3,NA)
var4=c(100,200,300,100,200,300)
df1=data.frame(cbind(var1,var2,var3,var4))
# Data frame 2 and three has two of the 4 variables and 4 has eveything
df2=df1[,c(1,2,4)]
df3=df1[,c(2,3,4)]
df4=df1
# I wanted to do this but it produces an error because the number of
variable differ
df=data.frame(rbind(df1,df2,df3,df4))
#I have figured out how to print the names of variable that do match the
'master' list (in this case df1):
# example with df3
names(df3[,na...
2009 Feb 19
3
Multiple merge, better solution?
...real situation, I have 26 different
data.frames with a common column. I can of course use merge many times
(see below) but what would be more sophisticated solution? For loop?
Any ideas?
DF1 <- data.frame(var1 = letters[1:5], a = rnorm(5))
DF2 <- data.frame(var1 = letters[3:7], b = rnorm(5))
DF3 <- data.frame(var1 = letters[6:10], c = rnorm(5))
DF4 <- data.frame(var1 = letters[8:12], d = rnorm(5))
g <- merge(DF1, DF2, by.x="var1", by.y="var1", all=T)
g <- merge(g, DF3, by.x="var1", by.y="var1", all=T)
merge(g, DF4, by.x="var1",...
2003 Sep 04
1
error in lm.fit
Hello R user,
I have several data frames with >100 columns and I did a linear regression
over time of each column
df1.lm <- lapply(df1, function(x) lm(x~year)$coeff[2])
that worked fine and I get slope of each column oder time - until I divided
df1 by df2
df3 <- df1/df2
> df3.lm <- lapply(df3, function(x) lm(x~year)$coeff[2])
Error in lm.fit(x, y, offset = offset, ...) :
0 (non-NA) cases
df3 has cases:
X106 X107 X108
1 -2.200986 -2.128744 -2.126991
2 -2.201284 -2.179806 -1.998352
3 -2.201589 -2.051754 -1.918321
4 -...
2012 Jan 02
2
Conditionally adding a constant
I am trying to add a constant to the previous value of a variable based on
certain conditions. Maybe there is a simple way to do this that I am missing
completely. I have given an example below:
df <- data.frame(x = c(1,2,3,4,5), y = c(10,20,30,NA,NA))
> df
x y
1 1 10
2 2 20
3 3 30
4 4 NA
5 5 NA
I want to add 2 to the previous value of y, if x exceeds 3 (also will have
to handle NAs in
2011 Jun 06
1
Merge two columns of a data frame
...quot;budget")
roots2 <- c("car insurance", "auto insurance")
roots3 <- c("car insurance", "auto insurance")
suffix3 <- c("quote", "quotes")
df1 <- expand.grid(prefix, roots, suffix)
df2 <- expand.grid(prefix2, roots2)
df3 <- expand.grid(roots3, suffix3)
df1; df2; df3
df1, df2, and df3 are seperate data structures with seperate columns for
root, prefix, and suffix.
Var1 Var2 Var3
1 cheap car insurance quote
2 budget car insurance quote
3 cheap auto insurance quote
4 budget auto insurance qu...
2011 Dec 22
1
finding overlapping regions
Dear All,
I am trying to finding overlapping regions in two diff datasets for that I
am using IRanges. But I am getting an error in the process of doing the
overlap. Advance thanks
df3.rl<-RangedData(IRanges(start=df3$V3,width=1),
+ space=df3$start)
Error in .normargSEW0(start, "start") :
'start' must be a numeric vector (or NULL)
Kumar
[[alternative HTML version deleted]]
2012 Jul 11
1
sapply question
Why does this sapply code change df3 but not df1?
Thanks
df1 <- read.table(text="
cola colb colc cold cole
1 NA 5 9 NA 17
2 NA 6 NA 14 NA
3 3 NA 11 15 19
4 4 8 12 NA 20
", header=TRUE)
df2 <-df1*2
df1
df2
df3 <-sapply(names(df1),function(x) {df1[[x]]<- df2[[x...
2004 Mar 09
5
Adding data.frames together
...ether so that they
become one, longer, data frame, i.e. - each of the slot vectors are
increased in length by the length of the added data frame vectors.
So if I have df1 with a slot A so that length(df1$A) = 100 and I have
df2 with a slot A so that length(df2$A)=200 then I need a method to
create df3 its slot A is the df1$A plus df2$A such that length(df3$A) =
300.
It does not appear that if you use data.frame to join two data frames it
just adds the slots of both sources to the destination data frame and
that is not what I want.
In my finally solution, I need to do this with multiple data.fr...
2004 Mar 15
1
gzfile & read.table on Win32
Hello ...
Are there any known problems or even gotchas to look out for when using a
gzfile connection in read.csv/read.table in Windows?
In the package PROcess, available at
www.bioconductor.org/repository/devel/package/html/PROcess.html
there are two files in the PROcess/inst/Test directory which are of the
extension *.csv.gz.
With both files, if I open up a gzfile connection, say:
vv <-
2011 Dec 07
2
Dividing rows when time is overlapping
Hi all,
I have dataframe that was created from the fusion of two dataframes. Both
spanned over the same time intervall but contained different information.
When I put them together, the info overlapped since there is no holes in the
time interval of one of the dataframe. Here is an example where the rows
"sp=A and B" are part of a first df and the rows "sp=C" come from a
2012 Jul 18
2
duplicate data between two data frames according to row names
...ot;ST002","ST003"),data=c(3,7))
I would like to add geographical coordinates of these weather stations
inside these two data.frames, according to the number of the weather
station.
All of my geographical coordinates for each of the 5 weather stations are
inside another data frame:
DF3 <-
data.frame(station=c("ST001","ST002","ST003","ST004","ST005"),lat=c(40,41,42,43,44),lon=c(1,2,3,4,5))
My question is: how can I put automatically these geographical coordinates
inside my first 2 data frames, according to the number of the wea...
2008 Mar 03
3
looping through data frames in a workspace
...gt;
> Could somebody show me how to loop through a list of dataframes? I want to
> be able to generically access their elements and do something with them.
>
> For instance, instead of this:
>
> df1<- data.frame(x=(1:5),y=(1:5));
> df2<- data.frame(x=(1:5),y=(1:5));
> df3<- data.frame(x=(1:5),y=(1:5));
> plot(df1$x,df1$y);
> plot(df2$x,df2$y);
> plot(df3$x,df3$y);
>
> I would like to do something like:
> (pseudocode)
> dfarray[1] = df1
> dfarray[2] = df2
> dfarray[3] = df3
> for (each i in dfarray) {
> plot(i$x, i$y);
> }
It...
2010 Sep 15
1
Format Data Issue??
R Users,
I am new to R and have tried to figure out how to automate this
process instead of using excel. I have read in this dataframe into r
with read.table. I need to reshape the data from the first table into
the format of the second table.
TractID StandID Species CruiseDate DBHClass TreesPerAcre
Carbon Stand 1 Loblolly Pine 5/20/2010 10 1.2
Carbon Stand 1 Loblolly Pine