Displaying 20 results from an estimated 8000 matches similar to: "vector operation using regexpr?"
2006 Mar 16
3
Did I use "step" function correctly? (Is R's step() function reliable?)
Hi all,
I put up an exhaustive model to use R's "step" function:
------------------------
mygam=gam(col1 ~ 1
+ col2 + col3 + col4
+ col2 ^ 2 + col3 ^ 2 + col4 ^ 2
+ col2 ^ 3 + col3 ^ 3 + col4 ^ 3
+ s(col2, 1) + s(col3, 1) + s(col4, 1)
+ s(col2, 2) + s(col3, 2) + s(col4, 2)
+ s(col2, 3) + s(col3, 3) + s(col4, 3)
+ s(col2, 4) + s(col3, 4) + s(col4, 4)
+ s(col2, 5) + s(col3,
2018 Feb 25
2
include
HI Jim and all,
I want to put one more condition. Include col2 and col3 if they are not
in col1.
Here is the data
mydat <- read.table(textConnection("Col1 Col2 col3
K2 X1 NA
Z1 K1 K2
Z2 NA NA
Z3 X1 NA
Z4 Y1 W1"),header = TRUE,stringsAsFactors=FALSE)
The desired out put would be
Col1 Col2 col3
1 X1 0 0
2 K1 0 0
3 Y1 0 0
4 W1 0 0
6 K2 X1
2018 Feb 25
0
include
Hi Val,
My fault - I assumed that the NA would be first in the result produced
by "unique":
mydat <- read.table(textConnection("Col1 Col2 col3
Z1 K1 K2
Z2 NA NA
Z3 X1 NA
Z4 Y1 W1"),header = TRUE,stringsAsFactors=FALSE)
val23<-unique(unlist(mydat[,c("Col2","col3")]))
napos<-which(is.na(val23))
preval<-data.frame(Col1=val23[-napos],
2018 Feb 25
0
include
Jim has been exceedingly patient (and may well continue to be so), but this smells like "failure to launch". At what point will you start showing your (failed) attempts at solving your own problems so we can help you work on your specific weaknesses and become self-sufficient?
--
Sent from my phone. Please excuse my brevity.
On February 25, 2018 7:55:55 AM PST, Val <valkremk at
2018 Feb 25
3
include
Thank you Jim,
I read the data as you suggested but I could not find K1 in col1.
rbind(preval,mydat) Col1 Col2 col3
1 <NA> <NA> <NA>
2 X1 <NA> <NA>
3 Y1 <NA> <NA>
4 K2 <NA> <NA>
5 W1 <NA> <NA>
6 Z1 K1 K2
7 Z2 <NA> <NA>
8 Z3 X1 <NA>
9 Z4 Y1 W1
On Sat, Feb 24, 2018 at 6:18 PM, Jim
2018 Feb 25
2
include
Sorry , I hit the send key accidentally here is my complete message.
Thank you Jim and all, I got it.
I have one more question on the original question
What does this "[-1] " do?
preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
Col2=NA,col3=NA)
mydat <- read.table(textConnection("Col1 Col2 col3
Z1 K1 K2
Z2
2018 Feb 25
0
include
hi Val,
Your problem seems to be that the data are read in as a factor. The
simplest way I can think of to get around this is:
mydat <- read.table(textConnection("Col1 Col2 col3
Z1 K1 K2
Z2 NA NA
Z3 X1 NA
Z4 Y1 W1"),header = TRUE,stringsAsFactors=FALSE)
preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
Col2=NA,col3=NA)
rbind(preval,mydat)
2018 Feb 24
0
include
Thank you Jim and all, I got it.
I have one more question on the original question
What does this "[-1] " do?
preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
Col2=NA,col3=NA)
mydat <- read.table(textConnection("Col1 Col2 col3
Z1 K1 K2
Z2 NA NA
Z3 X1 NA
Z4 Y1 W1"),header = TRUE)
2010 Jul 24
2
union data in column
Is there any function/way to merge/unite the following data
GENEID col1 col2 col3 col4
G234064 1 0 0 0
G234064 1 0 0 0
G234064 1 0 0 0
G234064 0 1
2010 Oct 11
2
Split rows depending on time frame
Hi,
I have the following data frame, where col2 is a startdate and col3 an
enddate
COL1 COL2 COL3
A 40462 40482
B 40462 40478
The above timeframe of 3 weeks I would like to splits it in weeks like this
COL1 COL2 COL3 COL4
A 40462 40468 1
A 40469 40475 1
A 40476 40482 1
B
2010 May 11
1
create a data.frame for aov
Hi R-experts,
I try to find a way to transfer a matrix to a data.frame that is used as input of aov.
can you give me advice for that?
>mdat <- matrix(c(1,2,3, 11,12,13), nrow = 2, ncol=3, byrow=TRUE, dimnames = list(c("row1", "row2"), c("Col1", "Col2", "Col3")))
>mdat
Col1 Col2 Col3
row1 1 2 3
row2 11 12 13
===>
2008 Mar 16
2
How to loop through all the columns in dataframe
Hi:
Can anyone advice me on how to loop and perform a
calculation through all the columns.
here's my data
xd<-
c(2.2024,2.4216,1.4672,1.4817,1.4957,1.4431,1.5676)
pd<-
c(0.017046,0.018504,0.012157,0.012253,0.012348,0.011997,0.012825)
td<- c(160524,163565,143973,111956,89677,95269,81558)
mydf<-data.frame(xd,pd,td)
trans<-t(mydf)
trans
I have these values that I need to
2004 Aug 18
1
header line generated write.table
I want to write following data frame into a CSV file:
Col1 Col2 Col3
Row1 1 1 1
Row2 2 2 2
where Row1, Row2 are the row names and Col1, Col2, Col3 are the column names.
The correct CSV file should be:
,"Col1","Col2","Col3"
Row1,1,1,1
Row2,2,2,2
However, the one generated by R using write.table(x, file="xyz.csv",
2018 Feb 24
2
include
Hi All,
I am reading a file as follow,
mydat <- read.table(textConnection("Col1 Col2 col3
Z2 NA NA
Z3 X1 NA
Z4 Y1 W1"),header = TRUE)
1. "NA" are missing should be replace by 0
2. value that are in COl2 and Col3 should be included in col1 before
they appear
in col2 and col3. So the output data looks like as follow,
X1 0 0
Y1 0 0
W1 0 0
Z2 0 0
Z3 X1 0
Z4 Y1
2018 Feb 24
3
include
On 24/02/2018 1:53 PM, William Dunlap via R-help wrote:
> x1 = rbind(unique(preval),mydat)
> x2 <- x1[is.na(x1)] <- 0
> x2 # gives 0
>
> Why introduce the 'x2'? x1[...] <- 0 alters x1 in place and I think that
> altered x1 is what you want.
>
> You asked why x2 was zero. The value of the expression
> f(a) <- b
> and assignments
2013 Jan 11
3
split & rbind (cast) dataframe
Hi,
I would like to split dataframe based on one colum and want
to connect the two dataframes by rows (like rbind). Here a small example:
# The orgininal dataframe
df1 <- data.frame(col1 = c("A","A","B","B"),col2 = c(1:4), col3 = c(1:4))
# The datafame how it could look like
df2 <- data.frame(A.col2 = c(1,2), A.col3 = c(1,2), B.col2 = c(3,4),
B.col3
2018 Feb 24
0
include
Hi Val,
Try this:
preval<-data.frame(Col1=unique(unlist(mydat[,c("Col2","col3")]))[-1],
Col2=NA,col3=NA)
rbind(preval,mydat)
Jim
On Sat, Feb 24, 2018 at 3:34 PM, Val <valkremk at gmail.com> wrote:
> Hi All,
>
> I am reading a file as follow,
>
> mydat <- read.table(textConnection("Col1 Col2 col3
> Z2 NA NA
> Z3 X1 NA
> Z4 Y1
2018 Feb 24
2
include
Thank you Jim
I wanted a final data frame after replacing the NA's to "0"
x1 = rbind(unique(preval),mydat)
x2 <- x1[is.na(x1)] <- 0
x2
but I got this,
[1] 0
why I am getting this?
On Sat, Feb 24, 2018 at 12:17 AM, Jim Lemon <drjimlemon at gmail.com> wrote:
> Hi Val,
> Try this:
>
>
2010 Jul 26
4
using string variable as order() function argument
Hello,
In my script I would like to use a loop, which sorts the dataframe
according to different columns, pointed by the string variable.
id col1 col2 col3
1 10 0 4 8
2 11 1 2 2
3 12 0 8 3
4 13 0 5 5
Usually the order() function can be used like this:
sorted = mytable**[order(column3) , ]
which results in properly sorted table:
**
2017 Jun 21
4
selecting dataframe columns based on substring of col name(s)
Suppose I have the following sort of dataframe, where each column name
has a common structure: prefix, followed by a number (for this example,
col1, col2, col3 and col4):
d = data.frame( col1=runif(10), col2=runif(10),
col3=runif(10),col4=runif(10))
What I haven't been able to suss out is how to efficiently
'extract/manipulate/play with' columns from the data frame, making use