similar to: Adding a new conditional column to a list of dataframes

Displaying 20 results from an estimated 4000 matches similar to: "Adding a new conditional column to a list of dataframes"

2018 Apr 15
0
Adding a new conditional column to a list of dataframes
> On Apr 15, 2018, at 4:08 AM, Allaisone 1 <Allaisone1 at hotmail.com> wrote: > > > Hi all .., > > > I have a list of 7000 dataframes with similar column headers and I wanted to add a new column to each dataframe based on a certain condition which is the same for all dataframes. > > > When I extract one dataframe and apply my code it works very well as
2018 Feb 25
4
reshaping column items into rows per unique ID
Hi All I have a datafram which looks like this : CustomerID DietType 1 a 1 c 1 b 2 f 2 a 3 j 4 c 4 c 4 f And I would like to reshape this so I can
2018 Feb 25
0
reshaping column items into rows per unique ID
Hi Allaisone, If you want a data frame as the output you will have to put up with a few NA values unless each Customer has the same number of diet types: a1df<-read.table(text="CustomerID DietType 1 a 1 c 1 b 2 f 2 a 3 j 4
2018 Feb 25
0
reshaping column items into rows per unique ID
I believe you need to spend time with an R tutorial or two: a data frame (presumably the "table" data structure you describe) can *not* contain "blanks" -- all columns must be the same length, which means NA's are filled in as needed. Also, 8e^5 * 7e^4 = 5.6e^10, which almost certainly will not fit into any local version of R (maybe it would in some server version --
2013 Feb 12
3
grabbing from elements of a list without a loop
Hello! # I have a list with several data frames: mylist<-list(data.frame(a=1:2,b=2:3), data.frame(a=3:4,b=5:6),data.frame(a=7:8,b=9:10)) (mylist) # I want to grab only one specific column from each list element neededcolumns<-c(1,2,0) # number of the column I need from each element of the list # Below, I am doing it using a loop: newlist<-NULL for(i in 1:length(mylist) ) {
2004 Aug 01
2
Strange Problem with "proj" and "aov" for split-plot analysis output
I'm using R 1.8.1 on Red Hat Linux 9. I've worked out the linear model decomposition by hand. Using "aov" with "Error" to fit a split-plot model, I get very different results depending on whether I use the "data" argument for "aov" or not. When I use the "data" argument, the ANOVA table from "summary" is correct but the
2010 Jun 28
2
ask a question about list in R project
my list al is as below: mylist=list(c(2,3),5,7) > mylist [[1]] [1] 2 3 [[2]] [1] 5 [[3]] [1] 7 How could I get the following FOUR lists: First one [[1]] [1] 3 [[2]] [1] 5 [[3]] [1] 7 Second one [[1]] [1] 2 [[2]] [1] 5 [[3]] [1] 7 Third One [[1]] [1] 2 3 [[2]] [1] 7 Last one [[1]] [1] 2 3 [[2]] [1] 5 Do I have to use 'for' loops? Please give me sone suggestions! Thank you
2004 Sep 12
2
boxplot() from list
I have a list containing 48 objects (each with 30 rows and 4 columns, all numeric), and wish to produce 4 boxplot series (with 48 plots in each) , one for each column of each object. Basically I want a boxplot from boxplot(mylist[[]][,i]) for i in 1:4. It seems that I can create a boxplot of length 48 from the entire list, but I don't seem able to subscript to return 4 boxplots from the list
2004 Nov 01
5
make apply() return a list
Hi, I have a dataframe (say myData) and want to get a list (say myList) that contains a matrix for each row of the dataframe myData. These matrices are calculated based on the corresponding row of myData. Using a for()-loop to do this is very slow. Thus, I tried to use apply(). However, afaik apply() does only return a list if the matrices have different dimensions, while my matrices have
2010 May 17
1
suggestions/improvements for recoding strategy
I am recoding some data. Many values that should be 1.5 are recorded as 1-2. Some example data and my solution is below. I am curious about better approaches or any other suggestions. Thanks! # example input data myData <- read.table(textConnection("id, v1, v2, v3 a,1,2,3 b,1-2,,3-4 c,,3,4"),header=TRUE,sep=",") closeAllConnections() # the first column is IDs so remove
2018 Apr 17
2
Time intervals in a datframe
Hi all I have a list of multiple datframes with the same column headers. The last column in each datframe contains a vector of "Interval" class after I have produced this column using "lubridate" package. I needed to convert my list of dataframes to be in a single dataframe for further analysis. I did this using the following syntax : SingleDataframe <- ldply
2018 Apr 17
0
Time intervals in a datframe
> On Apr 17, 2018, at 10:10 AM, Allaisone 1 <allaisone1 at hotmail.com> wrote: > > > Hi all > > I have a list of multiple datframes with the same column headers. The last column in each datframe contains a vector of "Interval" class after I have produced this column using "lubridate" package. I needed to convert my list of dataframes to be in a single
2009 May 26
1
Bug in "$<-.data.frame" yields corrupt data frame (PR#13724)
Full_Name: Steven McKinney Version: 2.9.0 OS: Mac OS X 10.5.6 Submission from: (NULL) (142.103.207.10) A corrupt data frame can be constructed as follows: foo <- matrix(1:12, nrow = 3) bar <- data.frame(foo) bar$NewCol <- foo[foo[, 1] == 4, 4] bar lapply(bar, length) > foo <- matrix(1:12, nrow = 3) > bar <- data.frame(foo) > bar$NewCol <- foo[foo[, 1] == 4, 4]
2005 Nov 29
1
Indexing variables within lapply?
Hello I am using R 2.2.0 with Windows XP. I've got a five element list object, each element containing two dataframes of equivalent size. > str(mylist) List of 1 $ data1:List of 2 ..$ data1a :`data.frame': 77 obs. of 63 variables: .. ..$ var1 : num [1:77] 0.41375 0.00056 1.43040 1.43528 0.61730 ... .. ..$ var2 : num [1:77] 1.154 1.686 0.673 0.800 0.760 ... ..
2006 Oct 17
2
Question about managing searching path
Hi all, I'm having sometrouble with managing the seach path, in a function , I need to attach some data set at the begining and detach them at the end, say, myfunction<- function() { attach(mylist); ............. detach(mylist) } , the problem is, since I am still debugging this code, sometimes it got error and ended before reaching the end, thus the data is left in the
2018 Feb 25
1
reshaping column items into rows per unique ID
Hi Allaisone, I took a slightly different approach but you might find this either as or more useful than your approach, or at least a start on the path to a solution you need. df1 <- data.frame(CustId=c(1,1,1,2,3,3,4,4,4),DietType=c("a","c","b","f","a","j","c","c","f"),
2009 Apr 29
1
Corrupt data frame construction - bug?
Hi useRs, A recent coding infelicity along these lines yielded a corrupt data frame. foo <- matrix(1:12, nrow = 3) bar <- data.frame(foo) bar$NewCol <- foo[foo[, 1] == 4, 4] bar lapply(bar, length) > foo <- matrix(1:12, nrow = 3) > bar <- data.frame(foo) > bar$NewCol <- foo[foo[, 1] == 4, 4] > bar X1 X2 X3 X4 NewCol 1 1 4 7 10 <NA> 2 2 5 8 11
2012 Oct 10
3
How to replicate SAS by group processing in R
Hello, I am trying to re-code all my programs from SAS into R. In SAS I use the following code: proc sort data=upper; by tdate stock_symbol expire strike; run; data upper1; set upper; by tdate stock_symbol expire strike; if first.expire then output; rename strike=astrike; run; on the following data set: tdate stock_symbol expiration strike 9/11/2012 C 9/16/2012
2012 Oct 19
4
Creating a new by variable in a dataframe
Hello, I have a dataframe w/ 3 variables of interest: transaction,date(tdate) & time(event_tim). How could I create a 4th variable (last_trans) that would flag the last transaction of the day for each day? In SAS I use: proc sort data=all6; by tdate event_tim; run; /*Create last transaction flag per day*/ data all6; set all6; by tdate event_tim; last_trans=last.tdate; Thanks
2017 Nov 18
3
Complicated analysis for huge databases
The loop : AllMAFs <- list() for (i in length(SeparatedGroupsofmealsCombs) { AllMAFs[[i]] <- apply( SeparatedGroupsofmealsCombs[[i]], 2, function(x)maf( tabulate( x+1) )) } gives these errors (I tried this many times and I'm sure I copied it entirely) :- Error in apply(SeparatedGroupsofmealsCombs[[i]], 2, function(x) maf(tabulate(x + : object 'i' not found > }