Displaying 20 results from an estimated 20000 matches similar to: "Simple programming question"
2007 May 20
2
Number of NA's in every second column
Hi R-users,
How do I calculate a number of NA's in a row of every second column in my
data frame?
As a starting point:
dfr <- data.frame(sapply(x, function(x) sample(0:x, 6, replace = TRUE)))
dfr[dfr==0] <- NA
So, I would like to count the number of NA in row one, two, three etc. of
columns X1, X3, X5 etc.
Thanks in advance
Lauri
[[alternative HTML version deleted]]
2007 Oct 15
2
Variable which has the maximum value of DF
Hi,
Suppose I have a data.frame like this
Lines <- "var1 var2 var3 var4 var5 var6
0 2 1 2 0 0
2 3 7 6 0 1
1.5 4 9 9 6 0
1.0 6 10 22 3 3
"
DF <- read.table(textConnection(Lines), skip=1)
names(DF) <- scan(textConnection(Lines), what = "", nlines = 1)
How do I find the
2008 Aug 07
2
List of "occurrence" matrices
R users,
I don't know if I can make myself clear but I'll give it a try. I have
a data.frame like this
x <- "var1,var2,var3,var4
a,b,b,a
b,b,c,b
c,a,a,a
a,b,c,c
b,a,c,a
c,c,b,b
a,c,a,b
b,c,a,c
c,a,b,c"
DF <- read.table(textConnection(x), header=T, sep=",")
DF
and I would like to sum all the combinations/occurences by a factor
(letter in this case) between
2007 Apr 02
1
RODBC, sqlQuery with NA:s
Hi R-users,
I'm trying to retrieve data from MS SQL database with RODBC's
sqlQuery-function:
temp <- sqlQuery(channel,"select *, (select text from table1 where
koodi='paa' and koodi2=paa) as tempor from table2")
str(temp)
…
$ var0 : num NA NA 1.6 NA NA 1.4 NA 1 NA NA ...
$ var1 : Factor w/ 45 levels "
2007 Mar 20
6
Select the last two rows by id group
Hi R-users,
Following this post http://tolstoy.newcastle.edu.au/R/help/06/06/28965.html ,
how do I get last two rows (or six or ten) by id group out of the data
frame? Here the example gives just the last row.
Sincere thanks,
Lauri
[[alternative HTML version deleted]]
2007 Sep 05
1
How to extract part of an array?
Hi,
How can I extract part of an array? I would like to extract table
Supported from this array. If this is not possible, how do I convert
array to list? I'm sorry this is not an reproducible example.
> spl <- tapply(temp$var1, list(temp$var2, temp$var3, temp$var3), mean)
> spl
, , Supported
07 08
A 68.38710 71.48387
B 21.67742 20.83871
C
2008 Nov 25
1
How to split DF into a list and avoid NULL elements in this list
Hello,
I'm trying to split my DF into a list using incremental loop. How can
I avoid NULL elements in this list?
DF <- data.frame(var1 = 1:10, var2 = 11:20, var3 = 21:30, var4 = 31:40)
x <- list()
i <- 1
while (i <= ncol(DF)-1) {
x[[i]] <- DF[, i:c(i+1)]
i <- i + 2
}
x
Many thanks,
Lauri
2009 Sep 08
7
Data separated by spaces, getting data into R using field lengths
I have a text file similar to this (separated by spaces):
x <- "DF12 This is an example 1 This
DF12 This is an 1232 This is
DF14 This is 12334 This is an
DF15 This 23 This is an example
"
and I know the field lengths of each variable (there is 5 variables in
this data set), which are:
varlength <- c(2, 2, 18, 5, 18)
How can I import this kind of data into R, using the varlength
2008 Feb 21
4
How to get names of a list into df:s?
R users,
I have a simple lapply question.
g <- list(a=1:3, b=4:6, c=7:9)
g <- lapply(g, function(x) as.data.frame(x))
lapply(g, function(x) cbind(x, var1 = rep(names(g), each=nrow(x))[1:nrow(x)]))
I get
$a
x var1
1 1 a
2 2 a
3 3 a
$b
x var1
1 4 a
2 5 a
3 6 a
$c
x var1
1 7 a
2 8 a
3 9 a
And I would like to have
$a
x var1
1 1 a
2 2 a
3 3 a
2008 Aug 20
2
Random sequence of days?
Dear list,
I tried to find a solution for this problem from the archives but
couldn't find any. I would like sample sequence of ten days from
vector d
d <- seq(as.Date("2007-02-12"), as.Date("2008-08-18"), by="days")
so that the days follow each other (sample(d, 10) is not the
appropriate solution). Any ideas?
Best regards,
Lauri
2008 Jan 14
6
Ceiling to the nearest ten?
R-users,
Is there a function for ceiling to the nearest ten?
a <- 1:10*4
a
[1] 4 8 12 16 20 24 28 32 36 40
The resulting vector should look like this ("ceiling to the nearest ten")
[1] 10 10 20 20 20 30 30 40 40 40
Thanks in advance
Lauri
2007 Sep 10
3
plot legend: combining filled boxes and lines
Hello,
I have difficulties combining boxes and lines in plot legend. I
searched previous R-posts and found this (with no solution):
http://tolstoy.newcastle.edu.au/R/help/06/07/30248.html. Is there a
way to avoid boxes behind the line legends?
x1 <- rnorm(100)
x2 <- rnorm(100, 2)
hist(x1, main = "", col = "orange",ylab = "density", xlab = "x", freq
=
2007 Aug 07
4
Number of days in each month
Hi R-users,
What is the best way to achieve a table which contains all days and months
between years 2007-2020? I would like to calculate number of days in each
month within those years (to data frame).
Regards,
Lauri
[[alternative HTML version deleted]]
2008 Mar 18
3
How to get week of the year, scale 1-52?
R users,
I have a vector of dates
days <- seq(as.Date("2007/1/1"), as.Date("2008/1/31"), "days")
and I would like to have week numbers from 1 to 52 for each year. How
do I do that? Now I get 00-53 using
format(days, "%W")
> range(format(days, "%W"))
[1] "00" "53"
I have read "Date and Time Classes in R" (R
2008 Jan 02
3
Find missing days
Hi,
I have a data.frame like this:
y <- rnorm(60)
lev <- gl(3,20, labels=paste("lev", 1:3, sep=""))
date1 <- as.Date(seq(ISOdate(2007,9,1), ISOdate(2007,11,5),
by=60*60*24))
date1 <- date1[-c(3,4,15,34,38,40)]
df <- data.frame(lev=lev, date1=date1, y=y)
I would like to produce a new data.frame with missing days in df$date1
in each df$lev, like this:
lev
2008 Oct 28
1
How to export text into separate text files
Hello,
I'm producing text from my data.frame using cat function. I would like
to use for loop to export each column in my data.frame into separate
text files. Here is the example code
r <- t(Indometh)
for (i in 1:ncol(r)) {
cat("Some text,", "\n")
cat("\n")
cat("More text, More text, More text")
cat("\n")
2007 Mar 11
1
recoding question
Hi R-users,
I have a data frame like this:
photographer category picture points
Hannu kalat limamikko 1
Teemu kalat verkkovaja 3
Hate kalat munat puoliks padassa 6
Hannu kalat isokala 8
Teemu kasvit, sienet ja muut eliöt harppi 2
Hate kasvit, sienet ja muut eliöt pyynikki 2
Petteri kasvit, sienet ja muut eliöt harmaaleppä 5
Lauri kasvit, sienet ja muut eliöt lumipuu 9
Teemu linnut kainostelua 1
2009 Jul 02
2
read.xls: number of sheets
Hi,
I'm trying to read several Excel sheets from an Excel file into a
list. I'm using
read.xls from package 'gdata'. I would like to know how I can
check the number of sheets before the loop (in the example below) so
that I could adjust the loop counter? Any suggestions?
DF.list <- list()
for (i in 1:4) {
DF.list[[i]] <- read.xls("sample_file.xls", sheet=i,
2010 Feb 08
4
Problem with R on USB-drive
Hi,
I installed R on USB-drive, but when I run Rgui.exe from bin folder, I get
this error:
-----------------------
R version 2.10.1 (2009-12-14)
Copyright (C) 2009 The R Foundation for Statistical Computing
ISBN 3-900051-07-0
R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for
2007 Mar 10
2
barplot, for loop?
Hi R-users,
I have a dataset like this:
kuvaaja
kuva
yhteispisteet
Hannu
isokala
8
Hannu
kaapin alta löytynyt
2
Hannu
kaapin alta löytynyt 2
8
Hannu
limamikko
1
Hannu
maukasta marmeladia
8
Hannu
skrinnareita
4
Hate
madekoukkujen suojelupyhimys
3
Hate
matka aikaan joka ei enää palaa
3
Hate
munat puoliks padassa
6
Hate
pyynikki
2
Hate
vailla armeerausta
2