Displaying 20 results from an estimated 10000 matches similar to: "Subsetting rows by multiple levels of selected values"
2004 Sep 09
2
Skipping panels in Lattice
Dear all,
I wish to generate a lattice boxplot which skips an empty cell in a design.
I have trawled r-help, scruitinized xyplot(lattice) help page, and merrily
reproduced examples of using skip from a couple of previous r-help queries
and the example given in Pinheiro & Bates. But I must be missing something...
Here's an example (running R 1.9.1 on Win2k):
# generate some data
df1
2009 Apr 09
2
failed when merging two dataframes, why
Hi, R-listers,
Failed, when I tried to merge df1 and df2 by "codetot" in df1 and "codetoto"
in df2. I want to know the reason and how to merge them together. Data
frames and codes I have used were listed as followed. Thanks a lot in
advance.
df1:
popcode codetot p3need
BCPy01-01 BCPy01-01-1 100.0000
BCPy01-01 BCPy01-01-2 100.0000
BCPy01-01 BCPy01-01-3 100.0000
BCPy01-02
2006 Jan 11
3
dataframes with only one variable
Subsetting from a dataframe with only one variable
returns a vector, not a dataframe.
This seems somewhat inconsistent.
Wouldn't it be better if subsetting would respect
the structure completely?
v1<-1:4
v2<-4:1
df1<-data.frame(v1)
df2<-data.frame(v1,v2)
sel1<-c(TRUE,TRUE,TRUE,TRUE)
> df1[sel1,]
[1] 1 2 3 4
> df2[sel1,]
v1 v2
1 1 4
2 2 3
3 3 2
4 4 1
--
Erich
2013 Feb 26
2
merging or joining 2 dataframes: merge, rbind.fill, etc.?
#I want to "merge" or "join" 2 dataframes (df1 & df2) into a 3rd
(mydf). I want the 3rd dataframe to contain 1 row for each row in df1
& df2, and all the columns in both df1 & df2. The solution should
"work" even if the 2 dataframes are identical, and even if the 2
dataframes do not have the same column names. The rbind.fill function
seems to work. For
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?
Dear expeRts,
What is the best approach to create a third data frame from two given ones, when
the new/third data frame has last column computed from the last columns of the two given
data frames?
## Okay, sounds complicated, so here is an example. Assume we have the two data frames:
df1 <- data.frame(Year=rep(2001:2010, each=2), Group=c("Group 1","Group 2"), Value=1:20)
2013 Jan 02
2
rbind: inconsistent behaviour with empty data frames?
The rbind on empty and nonempty data frames behaves inconsistently. I am
not sure if by design.
In the first example, first row is deleted, which may or may not be on
purpose:
df1 <- data.frame()
df2 <- data.frame(foo=c(1, 2), bar=c("a", "b"))
rbind(df1, df2)
foo bar
2 2 b
Now if we continue:
df1 <- data.frame(matrix(0, 0, 2))
names(df1) <- names(df2)
2009 Jan 21
3
merging several dataframes from a list
Hi there,
I have a list of dataframes (generated by reading multiple 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
2012 Jul 11
4
Help with loop
Hi,
I have two dataframes:
The first, df1, contains some missing data:
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
The second, df2, contains the following:
cola colb colc cold cole
1 1.4 0.8 0.02 1.6 0.6
I'm wanting all missing data in df1$cola to be replaced by the value of
df2$cola.
2008 Sep 14
5
difference of two data frames
Hello
I have 2 data frames DF1 and DF2 where DF2 is a subset of DF1:
DF1= data.frame(V1=1:6, V2= letters[1:6])
DF2= data.frame(V1=1:3, V2= letters[1:3])
How do I create a new data frame of the difference between DF1 and DF2
newDF=data.frame(V1=4:6, V2= letters[4:6])
In my real data, the rows are not in order as in the example I provided.
Thanks much
Joseph
[[alternative HTML version
2024 Jun 28
2
write.csv problems
Hello, All:
I'm getting strange errors with write.csv with some objects of class
c('findFn', 'data.frame'). Consider the following:
df1 <- data.frame(x=1)
class(df1) <- c('findFn', 'data.frame')
write.csv(df1, 'df1.csv')
# Error in x$Package : $ operator is invalid for atomic vectors
df2 <- data.frame(a=letters[1:2],
2009 Mar 16
3
sort data frame columns according to a list
HI,
I have searched the R-help achive, trying to find a way to sort columns in a data frame according to a specific list, but not be able to find a general way to do it.
My data frame contains columns, with each one named from a sample ID, and each sample was measured in a specific time, generating one column of data, now I would like to sort the columns according to the time course, so I have
2011 Apr 30
3
indexing into a data.frame using another data.frame that also contains values for replacement
Hello all,
I have a quandry I have been scratching my head about for a
while. I've searched the manual and the web and have not been able to
find an acceptable result, so I am hoping for some help.
I have two data frames and I want to index into the first using
the second, and replace the specific values I have indexed with more
values from the second data.frame. I can do this
2010 Dec 16
2
Compare two dataframes
Hello,
I have two dataframes DF1 and DF2 that should be identical but are not
(DF1 has some rows that aren't in DF2, and vice versa). I would like
to produce a new dataframe DF3 containing rows in DF1 that aren't in
DF2 (and similarly DF4 would contain rows in DF2 that aren't in DF1).
I have a solution for this problem (see self contained example below)
but it's awkward and
2012 Oct 11
1
as.data.frame.matrix() returns an invalid object
Hi,
Two ways to create what should normally be the same data frame:
> df1 <- data.frame(a=character(0), b=character(0))> df1
[1] a b
<0 rows> (or 0-length row.names)
> df2 <- as.data.frame(matrix(character(0), ncol=2,
dimnames=list(NULL, letters[1:2])))
> df2
[1] a b
<0 rows> (or 0-length row.names)
unique() works as expected except that I
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:
2012 Jun 03
2
merging single column from different dataframe
Hi all,
probably really simple to solve, but having no background in programming I
haven't been able to figure this out: I have two dataframes like
df1 <- data.frame(names1=c('aa','ab', 'ac', 'ad'), var1=c(1,5,7,12))
df2 <- data.frame(names2=c('aa', 'ab', 'ac', 'ad', 'ae'),
var2=c(3,6,9,12,15))
Now I want merge
2007 Aug 19
2
How to parse a string into the symbol for a data frame object
I have several data frames, eg:
> df1 <- data.frame(x=seq(0,10), y=seq(10,20))
> df2 <- data.frame(a=seq(0,10), b=seq(10,20))
It is common to create loops in R like this:
> for(df in list(df1, df2)){ #etc. }
This works fine when you know the name of the objects to put into the
list. I assume that the order of the objects in the list is respected
through the loop. Inside the
2004 Feb 19
1
Comparing two regression slopes
I would suggest the method of Sokal and Rholf (1995) S. 498, using the F
test.
Below I repeat the analysis by Spencer Graves:
Spencer:
> df1 <- data.frame(x=1:3, y=1:3+rnorm(3))
> df2 <- data.frame(x=1:3, y=1:3+rnorm(3))
> fit1 <- lm(y~x, df1)
> s1 <- summary(fit1)$coefficients
> fit2 <- lm(y~x, df2)
> s2 <- summary(fit2)$coefficients
> db <-
2007 May 05
1
loop in function
Dear Mailing-List,
I think this is a newbie question. However, i would like to integrate a
loop in the function below. So that the script calculates for each
variable within the dataframe df1 the connecting data in df2. Actually it
takes only the first row. I hope that's clear. My goal is to apply the
function for each data in df1. Many thanks in advance. An example is as
follows:
df1
2007 Oct 02
4
Strange names when creating a data.frame: Difference between <- and =
This is just a curiosity question. Why do the two
different syntaxes for df1 and df2 give such different
results in the names(dfx)?
Thanks
df1 <- data.frame(nas = c("A", "B" , "B" ,"C" ,"B",
"A", "D"),nums = c(3, 2, 1, 1, 2, 3, 7))
df2 <- data.frame(nas <- c("A", "B" ,