Displaying 14 results from an estimated 14 matches for "tempdf".
2010 Oct 13
4
Change global env variables from within a function
...lp.
In the process of trying to write a simple function to rename individual
column names in a data frame, I ran into the following problem: When I
rename the columns within my function, I can't seem to get it to apply
to the data frame in the global environment in a simple manner.
Given:
tempdf <- data.frame("a" = 1:6, "b" = 7:12)
#I can rename a to g this way:
names(tempdf)[names(tempdf)=="a"] <- "g"
#Wanting to simplify this for the future, I have the function:
colrename <- function(dframe, oldname, newname) {
names(dframe)[names(d...
2011 Jun 28
1
lattice multiple y-scale possible?
...fferent ranges of values, so it would be best to
have a separate y-axis range for each panel. Below is a basic example of
what I am trying to do. As is seen, the y-axes need to be scaled
individually to make this useful. Any information on how to do this
would be much appreciated:
rm(mydat)
rm(tempdf)
for (i in 1:5){
for (ii in 1:5){
dat <- sample(1:20)*10^ii
tempdf <- data.frame(dat)
tempdf$parameter <- paste("parameter ",ii,sep="")
tempdf$site <- paste("site",i,sep="")
if(!exists("mydat")) {mydat <- tempdf
}else {mydat <-...
2013 Mar 13
2
Extract letters from a column
Dear list:
I would like to extract three letters from first and second elements
in one column and make a new column.
For example below,
> tempdf = read.table("clipboard", header=T, sep='\t')
> tempdf
name var1 var2 abb
1 Tom Cruiser 1 6 TomCru
2 Bread Pett 2 5 BrePet
3 Arnold Schwiezer 3 7 ArnSch
> (p1 = substr(tempdf$name, 1, 3))
[1] "Tom" "Bre" "...
2011 May 19
1
Creating a "shifted" month (one that starts not on the first of each month but on another date)
...d next value after it
mydf$daynum<-as.numeric(format(mydate,"%d"))
library(zoo)
mydf$yearmon<-as.yearmon(mydf$mydate)
(mydf); str(mydf)
mydf$newfactor<-NA
for(i in unique(mydf$yearmon)){ # looping through "yearmon" (important
because true data has many years of data)
tempdf<-mydf[mydf$yearmon == i,]
which.month<-which(unique(mydf$yearmon)==i)
tempdf$newfactor[tempdf$daynum<20]<-which.month
tempdf$newfactor[tempdf$daynum>19]<-(which.month+1)
mydf[mydf$yearmon == i,]<-tempdf
}
(mydf)
--
Dimitri Liakhovitski
Ninah Consulting
www.ninah.com
2011 Jan 14
4
test
Hi, i have that table
Thesis Day A B C
1 0 83.43 90.15 22.97
1 0 85.50 94.97 16.62
1 0 83.36 95.38 20.70
1 0 84.47 92.16 23.58
1 0 83.98 95.33 19.39
1 0 82.86 93.78 24.55
1 0 83.39 92.67 19.56
1 0 85.17 95.24 17.95
1 0 81.62 93.32 28.49
1 0 82.99 92.85 19.73
1 0 81.11 95.67 27.20
1 0 83.39 94.69 16.51
1 0 79.56 89.87 30.39
1 0 80.54 93.32 21.76
1 0 82.11 92.58 22.17
1 14 85.65 94.00 19.19
1 14
2007 May 12
1
function similar to "get" that works for both an object, and elements of an object?
#Is there a single function similar to "get" that works for both an object, and elements of an object ?
#(I want the function to be able to return objects, and/or the deeper elements of an object.)
#(i.e. elements of a dataframe and/or list)?
#e.g.
tempdf = data.frame(a=c(4,5,6) , b=c(10,11,12) )
templist= list(x=tempdf, y=c(1,2))
get('tempdf') #works as desired
get('tempdf$a') #retrusn errro message
get('templist$x') #retrusn errro message
---------------------------------
8:00? 8:25? 8:40? Find a flick in no time...
2012 Aug 03
2
Recursive function calls
...at seemed to help with
this problem.
Thank you very much.
trim <- function(x) {
if(length(x)>1) sapply(x[1], trim)
gsub("^[[:space:]]+|[[:space:]]+$", "", x)
}
tempobj = ' many spaces '
tempvec = c(tempobj, tempobj)
templist = list(tempvec, tempvec)
tempdf = data.frame(x = tempvec, y = tempvec)
trim(tempobj)
trim(tempvec)
trim(templist)
trim(tempdf)
Thank you,
Gene Leynes
_____________________________________________
*Data Scientist*
*Mobile: 312-498-7702
**http://www.linkedin.com/in/geneleynes
*
<http://goog_598053156>*http://geneoram...
2007 Jul 15
1
Looping through a series of (csv) files
Dear Colleagues.
This should be a very common operation and I believe there should be a nice
way in R to handle it. I couldn't find it in the manual or by searching
online. I am wondering if I could ask for some help in this community.
I have 48 csv files; each stores the data for a specific month. The 48
corresponding months are consecutively from January, 2001 to December, 2004.
I name
2016 Jan 14
2
JDataFrame API
...JDataFrameBuilder()
.addColumn("Code", new Object[] {"WV", "VA", })
.addColumn("Description", new Object[] {"West Virginia", "Virginia"})
.toJson();
and in R script we would need to do this:
temp <- RJSONIO::fromJSON(json)
tempDF <- as.data.frame(temp)
which yields a data frame that looks like this:
> tempDF
Description Code
1 West Virginia WV
2 Virginia VA
It is my intention to deploy this project to Maven Central this week,
time permitting.
Questions and comments are welcomed.
Tom
2009 Dec 08
1
Printing 'k' levels of factors 'n' times each, but 'n' is unequal for all levels ?
...mmand,
but in my case, each level 'k' has an unequal number of elements.
Example with code is as below:
vc<-read.table("P:\\Transit\\CORRECT
files\\Everything-newest.csv",header=T, sep=",", dec=".", na.strings=NA,
strip.white=T)
vcdf<-data.frame(vc)
tempdf<-data.frame(cbind(vcdf[,1:3], vcdf[,429]))
newtemp<-na.exclude(tempdf)
newtemp[,2]<-factor(newtemp[,2])
groupmean<-tapply(newtemp[,4], newtemp[,2], mean)
newmark<-factor(groupmean, exclude=(groupmean==0 | groupmean==1))
newmark
This is what the output is (going up to 61 levels)
1...
2016 Jan 15
2
JDataFrame API
...ject[] {"WV", "VA", })
>> .addColumn("Description", new Object[] {"West Virginia", "Virginia"})
>> .toJson();
>>
>> and in R script we would need to do this:
>>
>> temp <- RJSONIO::fromJSON(json)
>> tempDF <- as.data.frame(temp)
>>
>> which yields a data frame that looks like this:
>>
>>> tempDF
>> Description Code
>> 1 West Virginia WV
>> 2 Virginia VA
>>
>> It is my intention to deploy this project to Maven Central this week,
&...
2016 Jan 15
0
JDataFrame API
...n("Code", new Object[] {"WV", "VA", })
> .addColumn("Description", new Object[] {"West Virginia", "Virginia"})
> .toJson();
>
> and in R script we would need to do this:
>
> temp <- RJSONIO::fromJSON(json)
> tempDF <- as.data.frame(temp)
>
> which yields a data frame that looks like this:
>
>> tempDF
> Description Code
> 1 West Virginia WV
> 2 Virginia VA
>
> It is my intention to deploy this project to Maven Central this week,
> time permitting.
>
> Q...
2010 Oct 15
0
nomianl response model
...lp.
In the process of trying to write a simple function to rename individual
column names in a data frame, I ran into the following problem: When I
rename the columns within my function, I can't seem to get it to apply
to the data frame in the global environment in a simple manner.
Given:
tempdf <- data.frame("a" = 1:6, "b" = 7:12)
#I can rename a to g this way:
names(tempdf)[names(tempdf)=="a"] <- "g"
#Wanting to simplify this for the future, I have the function:
colrename <- function(dframe, oldname, newname) {
names(dframe)[names(d...
2016 Jan 15
0
JDataFrame API
...t;VA", })
>>> .addColumn("Description", new Object[] {"West Virginia", "Virginia"})
>>> .toJson();
>>>
>>> and in R script we would need to do this:
>>>
>>> temp <- RJSONIO::fromJSON(json)
>>> tempDF <- as.data.frame(temp)
>>>
>>> which yields a data frame that looks like this:
>>>
>>>> tempDF
>>> Description Code
>>> 1 West Virginia WV
>>> 2 Virginia VA
>>>
>>> It is my intention to deploy this...