similar to: How to write a list object's name to a new dataframe in that list object

Displaying 20 results from an estimated 30000 matches similar to: "How to write a list object's name to a new dataframe in that list object"

2006 Aug 07
2
Retain only those records from a dataframe that exist in another dataframe
Dear R community, I have two dataframes "first" and "second" which share a unique identifier. I wish to make a new dataframe "third" retaining only the rows in "first" which also occur in "second". I have tried using merge but can't seem to figure it out. Any ideas? Thanks! Mark
2009 Dec 07
2
How to apply five lines of code to ten dataframes?
Hello R-helpers, I have 10 dataframes (named data1, data2, ... data10) and I would like to add 5 new columns to each dataframe using the following code: data1$LogDepth<-log10(data1[,2]/data1[,4]) data1$LogArea<-log10(data1[,3]/data1[,5]) data1$p<-2*data1[,6]/data1[,7] data1$Exp<-data1[,2]^(2/data1[,8]) data1$s<-data1[,3]/data1[,9] ...but I would prefer not to repeat this chunk of
2009 Jul 15
1
Averaging dataframes that are stored in a list
Dear R-helpers, I have a list containing 5000 elements, each element is a dataframe containing one ID column (identical over the 5000 dataframes) and 9 numeric variables, e.g. ID VAR1 VAR2 VAR3 ... VAR9 I would like to create a new dataframe containing the ID column and the mean values of the 9 numeric variables. So, the structure of this new dataframe would be identical to the structure of the
2006 Feb 25
2
Adding header lines to a dataframe that is exported using write.csv
I would like to export a dataframe to a .csv using: >write.csv(dataframe,"dataframe.csv") but I need to add four "header" lines to the csv that are not part of the dataframe (which itself has a line of column headers). The difficulty (for me, at least!) lies in the requirement that certain elements of the header (X, Y and the number of "Q"s - please see example
2009 Jun 17
2
How to translate a dataframe into the R code that makes that dataframe?
Hi, I am helping another R user (off list) and I would like to email her an R script containing the data she needs and the code to solve her problem. I have made a small dummy dataset, but instead of sending her a CSV I would prefer to send the data embedded in the script, so there would be a like in the script like: my.df<-c( etc, etc, etc I have made the dataframe (in a spreadsheet) and
2006 Feb 24
2
Sorting a dataframe by one column?
Given the following dataframe: A=1:10 B=(a-5)^2 DATAFRAME=data.frame(A,B) How can I sort DATAFRAME increasing (or decreasing, for that matter) by B without making reference to A, or any other column? I've read ?order and ?sort but cannot seem to figure this out. Thank you. Mark
2009 Jun 23
4
Apply as.factor (or as.numeric etc) to multiple columns
Hi R-helpers, I have a dataframe with 60columns and I would like to convert several columns to factor, others to numeric, and yet others to dates. Rather than having 60 lines like this: data$Var1<-as.factor(data$Var1) I wonder if it's possible to write one line of code (per data type, e.g. factor) that would apply a function (e.g., as.factor) to several (non-contiguous) columns. So, I
2008 Mar 25
2
Combining logical operators to extract columns from a dataframe
Hi R-helpers, I have a dataframe (called data) with 100 columns, the columns of which are named with integers ranging from 1900 to 1999. I wish to extract those columns which names are >=1950 and <=1970. I tried: data2<-subset(data,select=(names(data)>=1950 & names(data)<=1970)) but that doesn't work. Any ideas? Thanks! Mark [[alternative HTML version deleted]]
2011 Sep 27
4
Question concerning Box.test
Hi everyone, I've got a question concerning the function Box.test for testing autocorrelation in my data. My data consist of (daily) returns of several stocks over time (first row=time, all other rows=stock returns). I intend to perform a Box-Ljung test for my returns (for each stock). Since I have about 3000 stocks in my list, I'm not able to perform the test individually for each
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
2008 Mar 27
1
list as object in dataframe
Hi All, I need to place lists or vectors within dataframes as single elements. However when I try this: df=data.frame(y=1, x=I(list(c("a","b"), c("f","c"), c("a")))) df df[1,'x']=I(c("a","d")) I get this error, even though I am using I(): Error in `[<-.data.frame`(`*tmp*`, 1, "x", value =
2013 Jan 17
2
Naming an object after another object...can it be done?
Hello R-helpers, I have run the following line of code: x<-dat$col and now I would like to assign names(x) to be "dat$col" (e.g., a character string equal to the column name that I assigned to x). What I am trying to do is to assign columns in my dataframe to new objects called x and y. Then I will use x and y within a new function to make plots with informative axis labels (e.g.,
2009 Jun 30
1
How to wrap my (working) code in a loop or function? (loop/function newbie alert)
Dear R-helpers, I have split a dataframe into a list with five elements, with the following code: > datalist<-split(data,data$UNIT) I would now like to run some code (below) on each element of the list to extract rows from the list elements; then I would like to rbind the extracted rows into a new dataframe containing all of the extracted rows from all of the list elements. I don't
2009 Nov 24
2
How to identify the rows in my dataframe with a negative value in any column?
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20091124/27851110/attachment-0001.pl>
2008 Sep 26
1
How to update a column in a dataframe, more simply...
Hello, I would like to be able to update an existing column in a dataframe, like this... data$score[data$type=="1" & data$year=="2001"]<-data$score * 0.111 data$score[data$type=="1" & data$year=="2002"]<-data$score * 0.222 data$score[data$type=="1" & data$year=="2003"]<-data$score * 0.333 ...but, if possible,
2009 May 04
1
Please help me subset this dataframe, thanks...
Dear R-helpers, I have a dataframe called "trackpoints" with several columns including a column called "time", eg: > trackpoints ?? ? ? ?time 1 ? 12:00:00 2 ? 12:00:01 3 ? 12:00:02 . . . 298 12:04:57 299 12:04:58 300 12:04:59 I also have a dataframe called "data" that contains columns called "ID", "start" and "stop", eg: > data
2006 Feb 24
3
Sorting alphanumerically
I'm trying to sort a DATAFRAME by a column "ID" that contains alphanumeric data. Specifically,"ID" contains integers all preceeded by the character "g" as in: g1, g6, g3, g19, g100, g2, g39 I am using the following code: DATAFRAME=DATAFRAME[order(DATAFRAME1$ID),] and was hoping it would sort the dataframe by ID in the following manner g1, g2, g3, g6, g19,
2006 Jan 20
2
assign object to list
Dear all I want to generate a list like this: a <- data.frame(1:10) attr(a,'myattribute') <- 'something' b <- data.frame(11:20) attr(b,'myattribute') <- 'anything' mylist <- list(a,b) Is there a way to place the dataframes into the list giving them the attribute at the same time? I don't want to create all the dataframes in my workspace first.
2009 Jul 09
2
How to combine two rows (in a dataframe) into a third row?
Dear R-helpers, I have two rows in my dataframe: ID VALUE 1A 10 1B 15 and I would like to combine these two rows into a single (new) row in my dataframe: ID VALUE 1 25 ...simply by specifying a new value for ID and summing the two VALUES. I have been trying to do this with with rbind, but it's not working. I'd appreciate any pointers. Thanks, Mark Na [[alternative
2007 Feb 13
2
Computing stats on common parts of multiple dataframes
Folks, I have three dataframes storing some information about two currency pairs, as follows: R> a EUR-USD NOK-SEK 1.23 1.33 1.22 1.43 1.26 1.42 1.24 1.50 1.21 1.36 1.26 1.60 1.29 1.44 1.25 1.36 1.27 1.39 1.23 1.48 1.22 1.26 1.24 1.29 1.27 1.57 1.21 1.55 1.23 1.35 1.25 1.41 1.25 1.30 1.23 1.11 1.28 1.37 1.27 1.23 R> b EUR-USD NOK-SEK 1.23 1.22 1.21 1.36 1.28 1.61 1.23 1.34 1.21 1.22