Displaying 20 results from an estimated 8000 matches similar to: "Quickest way to access data.frame?"
2009 Jul 31
2
merging two data frame with colomns of different length
Dear all,
I am trying to merge two data frames based on a common column but for this
common column both data frame do not have the same length and associated
information. I checked previous exemples in the list but was not able to apply
them in my case... Is someone know how to do that? Below is my code with the
expected result:
# data frame 1
Id1 <- c(1,1,1,2,2,2,3,3,3)
Habit1 <-
2007 Feb 07
6
setting a number of values to NA over a data.frame.
This is probably a simple problem but I don't see a
solution.
I have a data.frame with a number of columns where I
would like 0 <- NA
thus I have df1[,144:157] <- NA if df1[, 144: 157] ==0
and df1[, 190:198] <- NA if df1[, 190:198] ==0
but I cannot figure out a way do this.
cata <- c( 1,1,6,1,1,NA)
catb <- c( 1,2,3,4,5,6)
doga <- c(3,5,3,6,4, 0)
dogb <- c(2,4,6,8,10,
2004 Aug 10
2
intersect two files
Hi all;
Im working with two datasets in R, say data1 and data2. Both datasets
are composed of several rows and columns (dataframe) and some of the
rows are identical in both datasets. Im wondering if there is any way to
remove from one set, say data1, the rows that are identical in the other
set, say data2, using R?
Thanks for any hint in advance
Christian
2011 May 04
3
SAPPLY function XXXX
Hello everyone,
I am attempting to write a function to count the number of non-missing
values of each column in a data frame using the sapply function. I have the
following code which is receiving the error message below.
> n.valid<-sapply(data1,sum(!is.na))
Error in !is.na : invalid argument type
Ultimately, I would like for this to be 1 conponent in a larger function
that will produce
2006 Sep 15
1
Table manipulation question
I have a table:
C1
RowName1 3
RowName2 2
and another table:
C2
RowName1 5.6
RowName1a 4.3
RowName2 NA
I want to join join the tables with matching rows:
C1 C2
RowName1 3 5.6
RowName2 2 NA
I'm thinking of something like:
2006 Mar 05
2
Wishlist: merge and subset to keep attributes (PR#8658)
Full_Name: Ulrike Gr?mping
Version: 2.2.1
OS: Windows
Submission from: (NULL) (84.190.139.94)
When importing data from SPSS, it is a nice feature of the package foreign that
it allows (option use.value.labels=F) to work with the original SPSS codes while
keeping the value labels as information in an attribute. Unfortunately, after
merging or subsetting, these attributes disappear.
The code
2007 Mar 01
3
Simplest question ever...
Let's say i have
a = c(1, 4, 5)
b = c(2, 6, 7)
and i have matrix m, what's an efficient way of access
m[1, 2], m[4, 6], m[5, 7]
like of course m[a, b] = is not going to do, but what's an expression that
will allow me to have that list?
Thanks!
--
View this message in context: http://www.nabble.com/Simplest-question-ever...-tf3329894.html#a9258932
Sent from the R help mailing list
2006 Mar 05
0
Wishlist: xtabs and table to optionally use attribute value labels (PR#8659)
Full_Name: Ulrike Gr?mping
Version: 2.2.1
OS: Windows
Submission from: (NULL) (84.190.139.94)
A wish somehow related to my wish 8658: Package foreign allows to import
categorical data from SPSS (and possibly other software) using the original
codes, which are often useful for data manipulation, since one can use already
available lists of codes from others who don't use R etc. The original
2010 Apr 29
3
Simple loop code
Hi fellow R Users,
I find that I typically rewrite my data specific to data in columns, which
is by no means efficient and I am struggling to break out of this bad habit
and utalise some of the excellent things R can do! I have tried to look at
'for' but I don't really follow it, and I wondered if anyone could help with
a simple example using my script so I could follow this and build
2007 Aug 28
2
Efficient way to parse string and construct data.frame
Hi all,
I have this list of strings
[1] "1 ,2 ,3" "4 ,5 ,6"
Is there an efficient way to convert it to data.frame:
V1 V2 V3
1 1 2 3
2 4 5 6
Like I can use strsplit to get to a list of split strings.. and then use say
a = strsplit(mylist, ",")
data.frame(V1 = lapply(a, function(x){x[1]}), V2 = lapply(a,
function(x){x[2]}),.....)
but i'm
2007 Jun 28
2
restructuring matrix
Hi all,
let's say I have matrix
People Desc Value
Mary Height 50
Mary Weight 100
Fanny Height 60
Fanny Height 200
Is there a quick way to form the following matrix?
People Height Weight
Mary 50 100
Fanny 60 200
(Assuming I don't know the length of people/desc and let's say these are
characters matrix.. I tried
2012 Apr 14
3
Choose between duplicated rows
Dear r experts,
Sorry for this basic question, but I can't seem to find a solution?
I have this data frame:
df <- data.frame(id = c("id1", "id1", "id1", "id2", "id2", "id2"), A =
c(11905, 11907, 11907, 11829, 11829, 11829), v1 = c(NA, 3, NA,1,2,NA), v2 =
c(NA,2,NA, 2, NA,NA), v3 = c(NA,1,NA,1,NA,NA), v4 = c("N",
2013 Apr 12
1
Removing rows that are duplicates but column values are in reversed order
Hi,
From your example data,
dat1<- read.table(text="
id1?? id2?? value
a????? b?????? 10
c????? d??????? 11
b???? a???????? 10
c????? e???????? 12
",sep="",header=TRUE,stringsAsFactors=FALSE)
#it is easier to get the output you wanted
dat1[!duplicated(dat1$value),]
#? id1 id2 value
#1?? a?? b??? 10
#2?? c?? d??? 11
#4?? c?? e??? 12
But, if you have cases like the one
2006 Sep 23
2
Question about merge()
If I want to do a join based on *two* matching fields in two data frames,
can merge() handle this? It appears to only handle a single matching column
-- do I need to make a "metacolumn" or is there some way to do this? E.g.:
Dataframe 1 contains columns A,B,C and Dataframe 2 contains A,B,D
I want an output A,B,C,D which places C and D together if A and B match
(otherwise, make two
2008 Jul 09
2
Parsing
Dear R users,
I have a big text file formatted like this:
x x_string
y y_string
id1 id1_string
id2 id2_string
z z_string
w w_string
stuff stuff stuff
stuff stuff stuff
stuff stuff stuff
//
x x_string1
y y_string1
z z_string1
w w_string1
stuff stuff stuff
stuff stuff stuff
stuff stuff stuff
//
x x_string2
y y_string2
id1
2005 Aug 10
1
Why only a "" string for heading for row.names with write.csv with a matrix?
Consider:
> x <- matrix(1:6, 2,3)
> rownames(x) <- c("ID1", "ID2")
> colnames(x) <- c("Attr1", "Attr2", "Attr3")
> x
Attr1 Attr2 Attr3
ID1 1 3 5
ID2 2 4 6
> write.csv(x,file="x.csv")
"","Attr1","Attr2","Attr3"
"ID1",1,3,5
2007 Apr 20
2
Fastest way to repeatedly subset a data frame?
Hi -
I have a data frame with a large number of observations (62,000 rows,
but only 2 columns - a character ID and a result list).
Sample:
> my.df <- data.frame(id=c("ID1", "ID2", "ID3"), result=1:3)
> my.df
id result
1 ID1 1
2 ID2 2
3 ID3 3
I have a list of ID vectors. This list will have anywhere from 100 to
1000 members, and
2011 Apr 25
2
Problem with ddply in the plyr-package: surprising output of a date-column
Hi Together,
I have a problem with the plyr package - more precisely with the ddply
function - and would be very grateful for any help. I hope the example
here is precise enough for someone to identify the problem. Basically,
in this step I want to identify observations that are identical in
terms of certain identifiers (ID1, ID2, ID3) and just want to save
those observations (in this step,
2012 Feb 22
1
Lattice and horizontally stacked density plots
Hello,
I am try to make a density plot where plots are stacked like the one
found here:
http://dsarkar.fhcrc.org/lattice/book/images/Figure_14_03_stdBW.png
I am facing problems, however. Using the code example below, I'd like
to generate a separate panel for each val of id2. Within each panel,
I'd like to have individual histograms each on separate lines based on
the value of id1. ?Note
2006 Feb 09
1
List Conversion
Hello,
I have a list (mode and class are list) in R that is many elements long and of the form:
>length(list)
[1] 5778
>list[1:4]
$ID1
[1] "num1"
$ID2
[1] "num2" "num3"
$ID3
[1] "num4"
$ID4
[1] NA
I'd like to convert the $ID2 value to be in one element rather than in two.?? It shows up as c(\"num2\", \"num3\") if I try to use