similar to: data.frame to character

Displaying 20 results from an estimated 10000 matches similar to: "data.frame to character"

2006 Apr 06
3
convert a data frame to matrix - changed column name
I have a question, which very easy to solve, but I can't find a solution. I want to convert a data frame to matrix. Here my toy example: > L3 <- c(1:3) > L10 <- c(1:6) > d <- data.frame(cbind(x=c(10,20), y=L10), fac=sample(L3, + 6, repl=TRUE)) > d x y fac 1 10 1 1 2 20 2 1 3 10 3 1 4 20 4 3 5 10 5 2 6 20 6 2 > is.data.frame(d) [1] TRUE > sapply(d,
2005 Jun 02
3
How to change all name of variables
Dear R-helpers, First I apologize if my question is quite simple I have a large datasets which more 100 variables. For a research I need to change all name of variables with add one or more letters on each variables. For example, > data(Pima.tr) > Pima.tr[1:5,] npreg glu bp skin bmi ped age type 1 5 86 68 28 30.2 0.364 24 No 2 7 195 70 33 25.1 0.163 55 Yes 3 5
2006 Jan 23
1
Sample rows in data frame by subsets
Hi, I need to resample rows in a data frame by subsets L3 <- LETTERS[1:3] d <- data.frame(cbind(x=1, y=1:10), fac=sample(L3, 10, repl=TRUE)) x y fac 1 1 1 A 2 1 2 A 3 1 3 A 4 1 4 A 5 1 5 C 6 1 6 C 7 1 7 B 8 1 8 A 9 1 9 C 10 1 10 A I have seen this used to sample rows with replacement d[sample(nrow(d), replace=T), ] x y fac 7 1 7 B 2
2005 Oct 13
1
expand.grid problem
Hi all, I want to make all possible combination from dataset below: V1 <- c(0,1,2) V2 <- c(0,1) V3 <- c(0,1) V4 <- c(0,1) V5 <- c(0,1) V6 <- c(0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20) V7 <- c(0,1,2,3,4,5,6) V8 <- c(0,1) V9 <- c(0,1) V10 <- c(0,1) V11 <- c(0,1) V12 <- c(0,1) V13 <- c(0,1) V14
2006 Sep 27
1
Impossible to merge with a zero rows data frame?
I'm trying to merge two data frames. One of them is a zero rows data frame. I'm using the merge parameter 'all.x = TRUE' so I'd expect to obtain all the rows of x. In fact the merge help says: all.x: logical; if 'TRUE', then extra rows will be added to the output, one for each row in 'x' that has no matching row in 'y'. These rows
2013 Dec 14
2
Change factor levels
Suppose I have a dataframe 'd' defined as L3 <- LETTERS[1:3] d0 <- data.frame(cbind(x = 1, y = 1:10), fac = sample(L3, 10, replace = TRUE)) (d <- d0[d0$fac %in% c('A', 'B'),]) x y fac 2 1 2 B 3 1 3 A 4 1 4 A 5 1 5 A 6 1 6 B 8 1 8 A Even though factor 'fac' in 'd' only has 2 levels, but it seems to bear the birthmark
2007 May 11
1
changing the mode of a factor (PR#9675)
Full_Name: Fr?d?ric Gosselin Version: 2.5 vs 2.4 and 2.2.1 OS: windows XP Submission from: (NULL) (195.221.118.52) ############# L3 <- LETTERS[1:3] (d <- data.frame(cbind(x=1, y=1:10), fac=as.factor(sample(L3, 10, repl=TRUE)))) mode(d[,3])<-"numeric" ############### when trying to change the mode of a column in a data.frame that is a factor to numeric(cf. preceding code),
2005 Oct 20
1
Windows 2000 crash while using rbind (PR#8225)
Windows 2000 reports that "Rgui.exe has generated errors and will be = closed by Windows. You will need to restart the program." when using = rbind.=20 df1 <- data.frame(cbind(x=3D1, y=3D1:1000), fac=3Dsample(LETTERS[1:3], = 1000, repl=3DTRUE)) df2 <- data.frame(cbind(x=3D1, y=3D1:10), fac=3Dsample(LETTERS[4:6], = 10, repl=3DTRUE)) df3 <- data.frame(cbind(x=3D1,
2009 Jan 06
2
Converting data frame to symmetric matrix
Dear Sir or Madam, I have the following data frame (which is just a toy example of my larger dataset) L3 <- LETTERS[1:3] x=c(1,1,2,2,3,3,4,4,5,5) y=1:10 d <- data.frame(cbind(x,y), fac=sample(L3, 10, replace=TRUE)) This data frame produces the following output x y fac 1 1 1 C 2 1 2 C 3 2 3 B 4 2 4 B 5 3 5 C 6 3 6 B 7 4 7 B 8 4 8 C 9 5 9 B 10 5
2006 Aug 24
5
Check values in colums matrix
Dear all, I apologize if my question is quite simple. I have a dataset (20 columns & 1000 rows) which some of columns have the same value and the others have different values. Here are some piece of my dataset: obj <- cbind(c(1,1,1,4,0,0,1,4,-1), c(0,1,1,4,1,0,1,4,-1), c(1,1,1,4,2,0,1,4,-1), c(1,1,1,4,3,0,1,4,-1), c(1,1,1,4,6,0,1,5,-1),
2005 Jun 15
4
how to change automatically 0=no and 1=yes
Dear R-helpers, I have dataset (data.frame) like below, x1 x2 x3 x4 x5 x6 x7 x8 x9 ... x1200 0 0 0 1 1 0 0 1 1 1 0 0 1 1 0 0 1 1 0 1 0 1 1 0 0 1 1 1 1 0 1 1 0 0 1 1 ... How can I change automatically 0=no and 1=yes. Thank you very much in advance. Kindly regards, Muhammad
2006 Aug 24
3
How to compare rows of two matrices
Dear all, I have a dataset train <- cbind(c(0,2,2,1,0), c(8,9,4,0,2), 6:10, c(-1, 1, 1, -1, 1)) test <- cbind(1:5, c(0,1,5,1,3), c(1,1,2,0,3) ,c(1, 1, -1, 1, 1)) I want to find which rows of train and test it different in its last column (column 4). The solution must be something like train [,1] [,2] [,3] [,4] [1,] 0 8 6 -1 [3,] 2 4 8 1 [4,] 1 0 9 -1
2006 Apr 11
2
About list to list - thanks
Thank you very much for your useful suggestions. These are exactly what I was looking for. foo <- list(foo1, foo2, foo3) lapply(foo, function(x) matrix(unlist(x), nrow = length(x), byrow = TRUE)) or lapply(foo, function(x) do.call('rbind', x)) Best, Muhammad Subianto On 4/11/06, Muhammad Subianto <msubianto at gmail.com> wrote: > Dear all, > I have a result my experiment
2005 May 18
3
How to convert array to c()
Dear R-helper, Is there possible to make this array: > a <- array(1:12, c(4, 3)) > a [,1] [,2] [,3] [1,] 1 5 9 [2,] 2 6 10 [3,] 3 7 11 [4,] 4 8 12 > like: c(1,5,9) c(2,6,10) c(3,7,11) c(4,8,12) Thank you very much in advance. Regards, Muhammad Subianto
2006 Jan 27
5
How to convert decimals to fractions
Dear all, Are there any functions to convert decimals to fractions in R? I have the result: > summary(as.factor(complete.ID)) 0 0.0133333333333333 0.04 2256 488 230 0.0666666666666667 0.0933333333333333 0.106666666666667 2342 310 726 0.133333333333333
2012 Jun 07
3
conditional statement to replace values in dataframe with NA
Hello and thanks for helping. #some data L3 <- LETTERS[1:3] dat1 <- data.frame(cbind(x=1, y=rep(1:3,2), fac=sample(L3, 6, replace=TRUE))) #When x==1 and y==1 I want to replace the 1 values with NA #I can select the rows I want: dat2<-subset(dat1,x==1 & y==1) #replace the 1 with NA dat2$x<-rep(NA,nrow(dat2) dat2$y<-rep(NA,nrow(dat2) #select the other rows and rbind
2006 Sep 03
3
Merge list to list - as list
Dear all, #Last week, I asked about merge x and y as list. #Now I have a dataset with list of list like: x <- list(list(matrix(1:20, 5, 4),matrix(1:20, 5, 4)), list(matrix(1:20, 5, 4),matrix(1:20, 5, 4))) y <- list(list(c(1, -1, -1, 1, 1),c(1, 1, -1, -1, -1)), list(c(1, 1, 1, 1, 1),c(1, 1, -1, 1, -1))) x y #I need merge x and y, I have tried with list.uni <-
2006 Aug 30
4
Barplot
Dear all, I have a dataset. I want to make barplot from this data. Zero1 <- " V1 V2 V3 V4 V5 V6 V7 V8 V9 1 1 0 0 0 1 0 0 0 Positive 2 0 0 1 0 1 0 1 1 Negative 3 0 0 1 0 0 0 1 1 Positive 4 0 1 0 1 1 1 0 1 Negative 5 0 0 1 0 1 1 0 0 Positive 6 0 1 0 0 1 1 1 1 Negative 7 1 0 1 1 1 1 1 1 Negative 8 0 0 0 0 1 0 0 1
2004 Dec 22
4
Make a table
Dear useR, I have a dataset like this below, > prevRND.dat <- read.table("C:\\workdir\\prevRND.txt", + header=FALSE, # No header. + col.names = c("X","Y","Z"), + sep = ",") > prevRND.dat X Y Z 1 A A 0.950933 2 A B 0.143600 3 A C 0.956133 4 B A
2006 Jun 20
2
expanded dataset and random number
Dear all R-users, (My apologies if this subject is wrong) I have dataset: mydat <- as.data.frame( matrix(c(14,0,1,0,1,1, 25,1,1,0,1,1, 5,0,0,1,1,0, 31,1,1,1,1,1, 10,0,0,0,0,1), nrow=5,ncol=6,byrow=TRUE)) dimnames(mydat)[[2]]