hi there
I have a big dataframe with columns such as:
ID, time, OS, IP
Each row of that dataframe corresponds to one entry. Within that dataframe for some IDs serveral entries (rows) exist.
I would like to get rid of those multiple rows (obviously the other attributes will differ for the same ID). Or put different: I only want one single...
I'm trying to replace elements of a data.frame containing "#N/A" with "NULL", and I'm running into problems:
foo <- data.frame("day"= c(1, 3, 5, 7), "od" = c(0.1, "#N/A", 0.4, 0.8))
indices_of_NAs <- which(foo == "#N/A")
replace(foo, indices_of_NAs, "NULL")
Error in [<-.data.frame(*tmp*, list, value = "NULL") :
new columns woul...
Hi all,
I wish to implement a "Last Observation Carried Forward" for a data set I am working on which has missing values at the end of it.
Here is a simple code to do it (question after it):
LOCF <- function(x)
{
# Last Observation Carried Forward (for a left to right series)
LOCF <- max(which(!is.na(x))) # the location of the...
test1 <- as.matrix(c(1, 2, 3, 4, 5))
row.names(test1) <- c("a", "d", "c", "b", "e")
test2 <- as.matrix(c(6, 7, 8, 9, 10))
row.names(test2) <- c("e", "d", "c", "b", "a")
test1
[,1]
a 1
d 2
c 3
b 4
e 5
test2
[,1]
e 6
d 7
c 8
b 9
a 10
How can I reorder test2 so that the rows are in the same order a...
Hello,
I have 13 quantitative variables in a data.frame (called 'UNCA').
The variables are named q01_a, q01_b, ...q01_m.
I want to create 13 new variables that have the same values but are coded as a factor.
I would like to name these 13 new variables q01_a.F, q01_b.F, ...q01_m.F.
Any help would be greatly appreciated!
...
Hello, I would like to create a new dataset where the following four conditions are all met.
rowSums(is.na(UNCA[,11:23]))<12
rowSums(is.na(UNCA[,27:39]))<12
rowSums(is.na(UNCA[,40:52]))<12
rowSums(is.na(UNCA[,53:65]))<12
Thanks!
...
Hi,
I have a data frame. Let's call him bob:
> head(bob)
phenotype exclusion
GSM399350 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1- Gr1- TER119-
GSM399351 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1- Gr1- TER119-
GSM399352 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1- Gr1- TER119-
GSM399353 3- 4- 8- 25+ 44+ 11b- 11c-...
I have code that at one place ends up with a list of data frames which I really want to convert to a single big data frame.
I got some pointers from an earlier question which was trying to do something similar but more complex.
Here's an example of what I am starting with (this is grossly simplified for illustration):
listOfDataFram...
df <- data.frame(var1=c('a', 'b', 'c'), var2=c('d', 'e', 'f'), freq=1:3)
What is the simplest way to expand the first two columns of the data.frame above, so that
each row appears the number of times specified in the column 'freq'?
In other words, go from this:
>df
var1 var2 freq
1 a d 1
2 b e 2
3 c f 3
...
Suppose my data looks like this:
2372 Kansas KS2000111 HUMBOLDT, CITY OF ATRAZINE 1.3 05/07/2006
9104 Kansas KS2000111 HUMBOLDT, CITY OF ATRAZINE 0.34 07/23/2006
9212 Kansas KS2000111 HUMBOLDT, CITY OF ATRAZINE 0.33 02/11/2007
2094 Kansas KS2000111 HUMBOLDT, CITY OF ATRAZINE 1.4 05/06/2007
16763 Kansas KS200011...
I'm getting a strange error when I run the following function:
TypeIDs=c(18283,18284,17119,17121,17123,17125,17127,17129,17131,17133,18367,18369,18371,18373,18375,18377,18379)
featsave<-function(featfile,TypeIDs=TypeIDs) {
mydata1<-read.table(featfile,header=TRUE)
mydata2<-subset(mydata1,TypeID %in% TypeIDs)
mydata<-as.dat...
Hi all,
I have the following 2 data.frames:
a1 <- data.frame(a = 1:5, b=letters[1:5])
a2 <- data.frame(a = 1:3, b=letters[1:3])
I want to find the row a1 has that a2 doesn't.
Is there a built in function for this type of operation?
(p.s: I did write a solution for it, I am simply curious if someone already made a more crafted code)...
Hello guys,
I'm trying to order this dataframe by population and date, so i'm using order() and rank() function :
idgeoville date population
1 5 1950 500
2 8 1950 450
3 4 1950 350
4 3 1950 350
5 4 2000 650
6 5 ...
Dear all,
I am trying to convert a uncommon date format into a standard date. Basically I have a dataset that contains a period with semiannual frequency formatted like: 206 denoting the second half of 2006, 106 denoting the first half and so forth. In order to rearrange it to 2006-06-01 respectively 2006-01-01, i have written a small ...
When I try to remove the last row from a single column data frame, I get a vector back instead of a data frame:
> df = data.frame(a=1:10)
> df
a
1 1
2 2
3 3
4 4
5 5
6 6
7 7
8 8
9 9
10 10
> df[-(length(df[,1])),]
[1] 1 2 3 4 5 6 7 8 9
The behavior I'm looking for is what happens when I use this command on a two-c...
Hello!
I am passing data from C# to R over a COM interface. When the data arrives in R it is housed in a 'Matrix'. Some of the functions that I use require that the data be inside a 'DataFrame' instead. I convert the data structure using
newDataFrame <- as.data.frame(oldMatrix)
The table of data reaches R just fine, once I make the...
I have a data.frame that looks like this
> head(df)
Memory Memory Memory Memory Memory Naive Naive
10472501 6.075714 5.898929 6.644946 6.023901 6.332126 8.087944 7.520194
10509163 6.168941 6.495393 5.951124 6.052527 6.404401 7.152890 8.335509
10496091 10.125575 9.966211 10.075613 10.310952...
Hi all,
I am using R to open up some saved .csv files in a particular pairwise manner and perform a statistical test ("mantel.rtest", found in the package "ade4"). The .csv files are sequentially named as either "fileAX" or "fileBY", where X and Y are integers.
I'd like to save the results of this test in a single file, but am runnin...
I'm using reshape in R to compute aggregate statistics over columns of a data.frame. Here's my data.frame:
> df
a a b b ID
1 1 1 1 1 1
2 2 3 2 3 2
3 3 5 3 5 3
which is just a little test data.frame to try and understand the reshape package. I melt, and then cast, to try and find the mean of the as and the bs:
> melt(df, id = "ID...
Is it possible to row bind two data frames that don't have the same set of columns? I am hoping to retain the columns that do not match after the bind.
I am new to R but figure that there has to be a fairly quick way to do this.
Many thanks,
Brock
...