[R] Basic help on DF creation row by row
arun
smartpink111 at yahoo.com
Tue Oct 1 20:19:45 CEST 2013
Hi,
Not sure if this helps.
deviceSummary <- data.frame(item = character(0) , value = numeric(0) , unit = character(0) ,stringsAsFactors=FALSE)
newlst<- list("primitiveSpace",1.1,"mm2")
deviceSummary[nrow(deviceSummary)+1,]<- newlst
newlst2<- list("primitiveSpace",2.2,"mm2")
deviceSummary[nrow(deviceSummary)+1,]<- newlst2
str(deviceSummary)
#'data.frame': 2 obs. of 3 variables:
# $ item : chr "primitiveSpace" "primitiveSpace"
# $ value: num 1.1 2.2
# $ unit : chr "mm2" "mm2"
deviceSummary
# item value unit
#1 primitiveSpace 1.1 mm2
#2 primitiveSpace 2.2 mm2
A.K.
----- Original Message -----
From: "rolf.kemper at renesas.com" <rolf.kemper at renesas.com>
To: r-help at r-project.org
Cc:
Sent: Tuesday, October 1, 2013 9:24 AM
Subject: [R] Basic help on DF creation row by row
Dear Experts
I'm very new to R and after some days or reading and testing I tried to make my first small application (and failed ...)
In general I would like to work with sqldf , ggplot2 to create some graphical output.
At present I got stuck with this:
PROG #############################################################################
deviceSummary <- data.frame(item = character(0) , value = numeric(0) , unit = character(0) )
print ( sapply(deviceSummary, class))
newRow <- c("primitiveSpace", 1.1 , "mm2")
deviceSummary <-rbind(deviceSummary , newRow )
print(deviceSummary)
newRow <- c("primitiveCellSpace", 2.2 , "mm2")
deviceSummary <-rbind(deviceSummary , newRow )
print(deviceSummary )
OUTPUT ############################################################################
item value unit
"factor" "numeric" "factor"
X.primitiveSpace. X.1.1. X.mm2.
1 primitiveSpace 1.1 mm2
X.primitiveSpace. X.1.1. X.mm2.
1 primitiveSpace 1.1 mm2
2 <NA> <NA> mm2
Warning messages:
1: In `[<-.factor`(`*tmp*`, ri, value = "primitiveCellSpace") :
invalid factor level, NA generated
2: In `[<-.factor`(`*tmp*`, ri, value = "2.2") :
invalid factor level, NA generated
Inserting the first record went fine , but the next one will fail as you can see.
Repeating only the first one (value1.1) went fine.
May be my imagination of DF is totally wrong. Hope someone can guide me.
Thanks a lot
Rolf
Rolf Kemper, Manager, Mixed Signal Design, Networking, Renesas Electronics Europe GmbH, , Arcadiastr. 10, 40472, Duesseldorf, Germany, Phone:+49 211
6503-1475, Fax:+49 211 6503-1540, mailto:Rolf.Kemper at renesas.com, http://www.renesas.eu
This message is intended only for the use of the address...{{dropped:24}}
______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
More information about the R-help
mailing list